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

CDAnalysis.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Program name: CDAnalysis.cxx
00004 //                                                                     
00005 // Package: CalDetTracker   
00006 //                                                                    
00007 // Coded by Jeff Hartnell Jul/2003 onwards
00008 //                                                                    
00009 // Purpose: To make plots and analyse the Tracker*.root files
00010 //                                                                    
00011 // Contact: jeffrey.hartnell@physics.ox.ac.uk                         
00013 
00014 #include <fstream>
00015 #include <cmath>
00016 #include <cassert>
00017 
00018 #include "TCanvas.h"
00019 #include "TChain.h"
00020 #include "TError.h"
00021 #include "TFile.h"
00022 #include "TF1.h"
00023 #include "TGraphErrors.h"
00024 #include "TH2F.h"
00025 #include "TLegend.h"
00026 #include "TProfile.h"
00027 #include "TProfile2D.h"
00028 #include "TStyle.h"
00029 #include "TTree.h"
00030 #include "TVector3.h"
00031 #include "TClonesArray.h"
00032 
00033 #include "CalDetPID/CalDetParticleType.h"
00034 #include "Calibrator/Calibrator.h"
00035 #include "Digitization/DigiSignal.h"
00036 #include "MessageService/MsgService.h"
00037 #include "MuELoss/MuEnergyLoss.h"
00038 #include "Conventions/Munits.h"
00039 #include "Conventions/StripEnd.h"
00040 #include "Validity/VldContext.h"
00041 
00042 #include "CalDetTracker/CDAnalysis.h"
00043 #include "CalDetTracker/CDSimpleMC.h"
00044 #include "CalDetTracker/CDTruthHitInfo.h"
00045 #include "CalDetTracker/CDPIDInfo.h"
00046 #include "CalDetTracker/CDTrackedHitInfo.h"
00047 #include "CalDetTracker/CDTrackInfo.h"
00048 #include "CalDetTracker/CDTrackerOptions.h"
00049 #include "CalDetTracker/CDXTalkHitInfo.h"
00050 
00051 using std::endl;
00052 using std::cout;
00053 using std::map;
00054 using std::vector;
00055 
00056 string CDAnalysis::fInputFileName="";
00057 
00058 ClassImp(CDAnalysis)
00059 
00060 CVSID("$Id: CDAnalysis.cxx,v 1.74 2007/07/03 16:01:27 hartnell Exp $");
00061 
00062 //......................................................................
00063 
00064 CDAnalysis::CDAnalysis()
00065 {
00066   MSG("CDAnalysis",Msg::kInfo)
00067       <<"Running CDAnalysis Constructor..."<<endl;
00068 
00069   //initialise variables
00070   fOutFile=0;//initialise output file pointer
00071   fTrackerTree=0;
00072   fOptTree=0;
00073   fTrkOpt=0;//tracking options
00074   fPIDInfo=0;
00075   fTrackInfo=0;
00076   fTrkHitInfo=0;
00077   fUnTrkHitInfo=0;
00078   fXTalkHits=0;
00079   fTruthHitInfo=0;
00080   
00081   fSnarl=-1;
00082   fSec=-1;
00083   fNumDeadChips=-1;
00084   fTemperature=-1;
00085   fBeamMomentum=0;
00086   fSimFlag=SimFlag::kUnknown;
00087   fRunNumber=0;
00088   fSubRun=0;
00089   fStartSnarl=0;
00090   fEndSnarl=0;
00091   fStartTime=0;
00092   fEndTime=0;
00093   fMainParticleEnergy=0;
00094   fEvents=-1;
00095 
00096   this->InitialiseLoopVariables();
00097   this->InitialiseHitInfoVariables();
00098   this->InitialisePidVariables();
00099 
00100   //set a default value of 1 so it stays as sigcor
00101   fSigCorsPerMip=1;
00102   fSigCorPerMEU=1;
00103   fScEnDepPerMEU=1;
00104   fRatioScEnToBeamEn=1;
00105   
00106   fMeuVsEvLenCutM=0;
00107   fSigCorVsDistM=0;
00108   fPeakLastPlane=0;
00109   fPeakPlaneSigCors=0;
00110   fMyPiMuCounter=0;
00111   fPidPiMuCounter=0;
00112   fMyElecCounter=0;
00113   fPidElecCounter=0;
00114   fBothPiMuCounter=0;
00115   fBothElecCounter=0;
00116   fAvTemperature=0;
00117 
00118   fS="";//general purpose string
00119   fDoReCalibration=false;//don't do recalibration by default
00120 
00122   //all data members are initialised by this point...
00124 
00125   this->MakeChain();
00126   this->SetRootFileObjects();
00127 
00128   //get the main particle energy
00129   fMainParticleEnergy=this->GetGreatestMainParticleEnergy();
00130   if (fMainParticleEnergy>0){
00131     MSG("CDAnalysis",Msg::kInfo)
00132       <<"Found main energy="<<fMainParticleEnergy<<endl;
00133     MSG("CDAnalysis",Msg::kInfo)
00134       <<"Beam Momentum from file="<<fBeamMomentum<<endl;
00135   }
00136 
00137   //setup some root stuff
00138   //include the under and overflow counts
00139   gStyle->SetOptStat(1111111);
00140   gStyle->SetOptFit(1111);
00141   gStyle->SetPalette(1,(Int_t*)0);
00142 
00143   //do these last in the constructor
00144   //set the values appropriately if possible
00145   this->SetSigCorPerMEU();
00146   this->SetScEnDepPerMEU();
00147   this->SetRatioScEnToBeamEn();
00148 
00149   MSG("CDAnalysis",Msg::kInfo)
00150       <<"Finished CDAnalysis Constructor"<<endl;
00151 }
00152 
00153 //......................................................................
00154 
00155 CDAnalysis::~CDAnalysis()
00156 {
00157   MSG("CDAnalysis",Msg::kDebug)
00158       <<"Running CDAnalysis Destructor..."<<endl;
00159   
00160   if (fOutFile){
00161     fOutFile->Close();
00162   }
00163 
00164   MSG("CDAnalysis",Msg::kDebug)
00165       <<"Finished CDAnalysis Destructor"<<endl;
00166 }
00167 
00168 //......................................................................
00169 
00170 void CDAnalysis::InitialiseLoopVariables()
00171 {
00172   MSG("CDAnalysis",Msg::kDebug)<<"Initialising loop variables..."<<endl;
00173 
00174   fFirstPlane=69;
00175   fLastPlane=-1;
00176   fLastPlaneOdd=-1;
00177   fLastPlaneEven=-1;
00178 
00179   fNumPlanesHitAll.clear();
00180   fNumPlanesHit25.clear();
00181   fNumPlanesHitTrk.clear();
00182   fNumPlanesHitPeCut.clear();
00183   fNumPlanesHitPeCut10.clear();
00184 
00185   fNumHitsPerPlane=-1;
00186   fNumHitsPerPlane25=-1;
00187   fNumHitsPerPlanePeCut10=-1;
00188   fStripsFromCentrePeCut=-1;
00189 
00190   //variables to calc av strip for ps muon cut
00191   fAvStrip=-1;
00192   fStCount=0;
00193   fAvStrip1=-1;
00194   fStCount1=0;
00195   fAvStrip2=-1;
00196   fStCount2=0;
00197 
00198   fLowScint_Tof=1e9;
00199   fUpScint_Tof=-1e9;
00200 
00201   MSG("CDAnalysis",Msg::kDebug)<<"Initialisation complete"<<endl;
00202 }
00203 
00204 //......................................................................
00205 
00206 void CDAnalysis::InitialisePidVariables()
00207 {
00208   //these are the SI variables
00209   fTriggerPMT=-1;
00210   fFafErr=-1;
00211   fSparseErr=-1;
00212   fTrigSource=-1;
00213 
00214   fKovADC1=-1;
00215   fKovTimeStamp1=-1;
00216   fKovADC2=-1;
00217   fKovTimeStamp2=-1;
00218   fKovADC3=-1;
00219   fKovTimeStamp3=-1;
00220 
00221   fSnarlTimeFrame=-1;
00222   fSnarlMinTimeStamp=0;
00223   fSnarlMaxTimeStamp=0;
00224 
00225   fTofTDC0=-1;
00226   fTofTDC1=-1;
00227   fTofTDC2=-1;
00228   fTofADC0=-1;
00229   fTofADC1=-1;
00230   fTofADC2=-1;
00231   fTofADCTimeStamp0=-1;
00232   fTofADCTimeStamp1=-1;
00233   fTofADCTimeStamp2=-1;
00234   fTofTimeStamp=-1;//don't use this, use fTofADCTimeStamp1==TTAG
00235 
00236   fTickSinceLast=-1;
00237 
00238   //these are the PID variables
00239   fNoOverlap=kFALSE;
00240   fInCERTime=kFALSE;
00241   fPIDType=0;
00242   fNoOverlapBits=0; 
00243   fInCERTimeBits=0; 
00244   fOLChi2=0;
00245 }
00246 
00247 //......................................................................
00248 
00249 void CDAnalysis::InitialiseHitInfoVariables()
00250 {
00251   fTime=0;
00252 
00253   fPlane=-1;
00254   fResultOdd=-1;
00255   fResultEven=-1;
00256   fStrip=-1;
00257   fStripend=-1;
00258   fTransPos=-1;
00259 
00260   fO1=false;
00261   fO2=false;
00262   fE1=false;
00263   fE2=false;
00264 
00265   fChargeAdc=-1;
00266   fChargeMip=-1;
00267   fChargeSigCor=-1;
00268   fChargeSigLin=-1;
00269   fChargePe=-1;
00270   fGain=-1;
00271 }
00272 
00273 //......................................................................
00274 
00275 void CDAnalysis::WriteOutHistos() const
00276 {
00277   //write out the histos to the file, if it's open
00278   if (fOutFile){
00279     if (fOutFile->IsWritable()){
00280       fOutFile->cd();
00281 
00282       //create a tree and set branches      
00283       TTree runInfo("runInfo","runInfo");
00284       //have to create local variables here
00285       //I think it's something to do with the fact that they are
00286       //read in on other trees in this class as well???
00287       //No, actually not because fSigCorsPerMip is not in a tree
00288       //don't understand this crazyness!
00289       Int_t lSimFlag=fSimFlag;
00290       runInfo.Branch("SimFlag",&lSimFlag,"SimFlag/I");
00291       Float_t lBeamMomentum=fBeamMomentum;
00292       runInfo.Branch("BeamMomentum",&lBeamMomentum,"BeamMomentum/F");
00293       Int_t lRunNumber=fRunNumber;
00294       runInfo.Branch("RunNumber",&lRunNumber,"RunNumber/I");
00295       Int_t lSubRun=fSubRun;
00296       runInfo.Branch("SubRun",&lSubRun,"SubRun/I");
00297       Int_t lRunPeriod=this->RunNumber2RunPeriod(fRunNumber);
00298       runInfo.Branch("RunPeriod",&lRunPeriod,"RunPeriod/I");
00299       Int_t lStartTime=fStartTime;
00300       runInfo.Branch("StartTime",&lStartTime,"StartTime/I");
00301       Int_t lEndTime=fEndTime;
00302       runInfo.Branch("EndTime",&lEndTime,"EndTime/I");
00303       Int_t lStartSnarl=fStartSnarl;
00304       runInfo.Branch("StartSnarl",&lStartSnarl,"StartSnarl/I");
00305       Int_t lEndSnarl=fEndSnarl;
00306       runInfo.Branch("EndSnarl",&lEndSnarl,"EndSnarl/I");
00307       Float_t lAvTemperature=fAvTemperature;
00308       runInfo.Branch("AvTemperature",&lAvTemperature,"AvTemperature/F");
00309 
00310       Float_t lSigCorsPerMip=fSigCorsPerMip;
00311       runInfo.Branch("SigCorsPerMip",&lSigCorsPerMip,"SigCorsPerMip/F");
00312       Float_t lScEnDepPerMEU=fScEnDepPerMEU;
00313       runInfo.Branch("ScEnDepPerMEU",&lScEnDepPerMEU,"ScEnDepPerMEU/F");
00314       Float_t lRatioScEnToBeamEn=fRatioScEnToBeamEn;
00315       runInfo.Branch("RatioScEnToBeamEn",&lRatioScEnToBeamEn,
00316                      "RatioScEnToBeamEn/F");
00317       Float_t lPeakLastPlane=fPeakLastPlane;
00318       runInfo.Branch("PeakLastPlane",&lPeakLastPlane,
00319                      "PeakLastPlane/F");
00320       Float_t lPeakPlaneSigCors=fPeakPlaneSigCors;
00321       runInfo.Branch("PeakPlaneSigCors",&lPeakPlaneSigCors,
00322                      "PeakPlaneSigCors/F");
00323       Float_t lSigCorVsDistM=fSigCorVsDistM;
00324       runInfo.Branch("SigCorVsDistM",&lSigCorVsDistM,
00325                      "SigCorVsDistM/F");
00326       Float_t lMeuVsEvLenCutM=fMeuVsEvLenCutM;
00327       runInfo.Branch("MeuVsEvLenCutM",&lMeuVsEvLenCutM,
00328                      "MeuVsEvLenCutM/F");
00329       Int_t lEvLenCutMin=-1;
00330       Int_t lEvLenCutMax=-1;
00331       this->GetEvLenMinMax(lEvLenCutMin,lEvLenCutMax);
00332       runInfo.Branch("EvLenCutMin",&lEvLenCutMin,"EvLenCutMin/I");
00333       runInfo.Branch("EvLenCutMax",&lEvLenCutMax,"EvLenCutMax/I");
00334 
00335       //pid counters
00336       Int_t lMyPiMuCounter=fMyPiMuCounter;
00337       runInfo.Branch("MyPiMuCounter",&lMyPiMuCounter,"MyPiMuCounter/I");
00338       Int_t lPidPiMuCounter=fPidPiMuCounter;
00339       runInfo.Branch("PidPiMuCounter",&lPidPiMuCounter,
00340                      "PidPiMuCounter/I");
00341       Int_t lMyElecCounter=fMyElecCounter;
00342       runInfo.Branch("MyElecCounter",&lMyElecCounter,"MyElecCounter/I");
00343       Int_t lPidElecCounter=fPidElecCounter;
00344       runInfo.Branch("PidElecCounter",&lPidElecCounter,
00345                      "PidElecCounter/I");
00346       Int_t lBothPiMuCounter=fBothPiMuCounter;
00347       runInfo.Branch("BothPiMuCounter",&lBothPiMuCounter,
00348                      "BothPiMuCounter/I");
00349       Int_t lBothElecCounter=fBothElecCounter;
00350       runInfo.Branch("BothElecCounter",&lBothElecCounter,
00351                      "BothElecCounter/I");
00352 
00353       //fill and write      
00354       runInfo.Fill();
00355       runInfo.Write();
00356 
00357       MSG("CDAnalysis",Msg::kInfo)
00358         <<"Writing histos to: "<<fOutFile->GetName()<<" ..."<<endl;
00359       fOutFile->Write();
00360       //fOutFile->Close();//this makes histos disappear from
00361       //the canvases for some strange reason!
00362     }
00363     else {
00364       MSG("CDAnalysis",Msg::kWarning)
00365         <<"File not writable!"<<endl;
00366     }
00367   }
00368 }
00369 
00370 //......................................................................
00371 
00372 void CDAnalysis::InputFileName(string f)
00373 {
00374   MSG("CDAnalysis",Msg::kInfo)
00375     <<"Running with input file name="<<f<<endl;
00376   fInputFileName=f;
00377 }
00378 
00379 //......................................................................
00380 
00381 vector<string> CDAnalysis::MakeFileList()
00382 {
00384 
00385   vector<string> fileList;
00386   
00387   if (fInputFileName!=""){
00388     ifstream inputFile(fInputFileName.c_str());
00389 
00390     //check if file exists
00391     if (inputFile){
00392       //variables to hold input from file
00393       string file="";
00394    
00395       //read in from the text file and fill objects
00396       while(inputFile>>file) {
00397         MSG("CDAnalysis",Msg::kDebug)
00398           <<"Found input file name="<<file<<endl;
00399         fileList.push_back(file);
00400       }
00401       MSG("CDAnalysis",Msg::kDebug)
00402         <<"Files names found in txt file="<<fileList.size()<<endl;
00403     }
00404     else{
00405       MSG("CDAnalysis",Msg::kFatal)
00406         <<endl<<endl
00407         <<"***********************************************************"
00408         <<endl<<"Input txt file of file names does not exist!"<<endl
00409         <<"InputFileName="<<fInputFileName<<endl
00410         <<"***********************************************************"
00411         <<endl<<endl<<"Program will exit here"<<endl;
00412       exit(0);
00413     }
00414   }
00415   //return the fileList if files were found
00416   if (fileList.size()>0) return fileList;
00417   
00418   //Check the env variable to find files
00419   char* envVariable=getenv("CDDATA");
00420   if (envVariable==NULL){
00421     MSG("CDAnalysis",Msg::kFatal)
00422       <<endl<<endl
00423       <<"*************************************************************"
00424       <<endl<<"Environmental variable CDDATA not set!"<<endl
00425       <<"Please set CDDATA to the directory containing the"
00426       <<" Tracker*.root files"<<endl
00427       <<"Note: If more than one file is found they will be"
00428       <<" concatenated and treated as one"<<endl
00429       <<"*************************************************************"
00430       <<endl<<endl<<"Program will exit here"<<endl;
00431     exit(0);
00432   }
00433   string sEnv=envVariable;
00434   MSG("CDAnalysis",Msg::kInfo)
00435     <<"Looking for Tracker*.root files using the env variable"<<endl
00436     <<"CDDATA="<<sEnv<<endl;
00437   sEnv+="/Tracker*.root";
00438   fileList.push_back(sEnv);
00439 
00440   return fileList;
00441 }
00442 
00443 //......................................................................
00444 
00445 void CDAnalysis::MakeChain()
00446 {
00447   //get the files to open
00448   vector<string> fileList=this->MakeFileList();
00449 
00450   //create a chain with TrackerTree
00451   fTrackerTree=new TChain("TrackerTree");
00452   fOptTree=new TChain("TrackerOptions");
00453 
00454   Int_t nf=0;
00455   //add the files to the chain
00456   for (vector<string>::iterator file=fileList.begin();
00457        file!=fileList.end();++file){
00458     
00459     //test if file already exists
00460     ifstream openOk((*file).c_str()); 
00461 
00462     //check if a wildcard was used because ifstream can't open wildcards
00463     Int_t stars=(*file).find("*");
00464     Int_t quest=(*file).find("?");
00465 
00466     //check if file existed
00467     if (!openOk && !(quest>=0 || stars>=0)){
00468       MSG("CDAnalysis",Msg::kInfo)
00469         <<endl<<endl
00470         <<"***********************************************************"
00471         <<endl<<"Can't find file="<<*file<<endl
00472         <<"Note: you can't use '~/'. It has to be the full path"<<endl
00473         <<"***********************************************************"
00474         <<endl<<endl
00475         <<"Exiting here!"<<endl;
00476       exit(0);
00477     }
00478     
00479     MSG("CDAnalysis",Msg::kInfo)<<"Adding file="<<*file<<endl;
00480     nf+=fTrackerTree->Add((*file).c_str());
00481     fOptTree->Add((*file).c_str());
00482   }
00483 
00484   if(nf==0){
00485     MSG("CDAnalysis",Msg::kFatal)
00486       <<endl<<endl
00487       <<"*************************************************************"
00488       <<endl<<"No Tracker*.root files found"<<endl
00489       <<"Please set CDDATA to the directory containing the"
00490       <<" Tracker*.root files"<<endl
00491       <<"Or give the txt file containing the files to be input"<<endl
00492       <<"Note: If more than one file is found they will be"
00493       <<" concatenated in a TChain and treated as one"<<endl
00494       <<"*************************************************************"
00495       <<endl<<endl<<"Program will exit here"<<endl;
00496     exit(0);
00497   }
00498     
00499   MSG("CDAnalysis",Msg::kInfo) 
00500     <<"Tracker Tree information:"<<endl;
00501   fTrackerTree->Show(0);
00502   MSG("CDAnalysis",Msg::kInfo) 
00503     <<"Options Tree information:"<<endl;
00504   fOptTree->Show(0);
00505   //fTrackerTree->Print()
00506   
00507   MSG("CDAnalysis",Msg::kInfo)
00508     <<endl<<"Analysing "<<nf<<" file(s). Reading from disk..."<<endl;
00509 }
00510 
00511 //......................................................................
00512 
00513 void CDAnalysis::SetRootFileObjects()
00514 {
00515   MSG("CDAnalysis",Msg::kDebug)
00516     <<"Running the SetRootFileObjects method..."<<endl;
00517 
00518   //tracker options tree
00519   fOptTree->SetBranchAddress("SimFlag",&fSimFlag);
00520   fOptTree->SetBranchAddress("Run",&fRunNumber);
00521   fOptTree->SetBranchAddress("SubRun",&fSubRun);
00522   fOptTree->SetBranchAddress("TrackerOptions",fTrkOpt);
00523   fOptTree->SetBranchAddress("StartTime",&fStartTime);
00524   fOptTree->SetBranchAddress("EndTime",&fEndTime);
00525   fOptTree->SetBranchAddress("StartSnarl",&fStartSnarl);
00526   fOptTree->SetBranchAddress("EndSnarl",&fEndSnarl);
00527   fOptTree->SetBranchAddress("BeamMomentum",&fBeamMomentum);
00528 
00529   //set the number of events in the tree
00530   Int_t events=static_cast<Int_t>(fOptTree->GetEntries());
00531   MSG("CDAnalysis",Msg::kDebug)
00532     <<"OptTree has "<<events<<" events"<<endl;
00533   if (events>0){
00534     //get the snarl/event
00535     fOptTree->GetEvent(0); 
00536     MSG("CDAnalysis",Msg::kInfo)
00537       <<"File has run="<<fRunNumber<<", subrun="<<fSubRun
00538       <<", SimFlag="<<SimFlag::AsString(fSimFlag)
00539       <<", beam momentum="<<fBeamMomentum<<endl
00540       <<"Time="<<fStartTime<<"->"<<fEndTime
00541       <<", snarl="<<fStartSnarl<<"->"<<fEndSnarl<<endl; 
00542   }
00543 
00544   //set the branch to point at the track info object and pid
00545   fTrackerTree->SetBranchAddress("TrackInfo",&fTrackInfo);
00546   fTrackerTree->SetBranchAddress("Snarl",&fSnarl);
00547   fTrackerTree->SetBranchAddress("NumDeadChips",&fNumDeadChips);
00548   fTrackerTree->SetBranchAddress("Sec",&fSec);
00549   fTrackerTree->SetBranchAddress("Temperature",&fTemperature);
00550 
00551   //check and set pid info branch
00552   if (fTrackerTree->GetBranchStatus("PIDInfo")){
00553     fTrackerTree->SetBranchAddress("PIDInfo",&fPIDInfo);
00554   }
00555   else{
00556     MSG("CDAnalysis",Msg::kInfo)
00557       <<"PIDInfo branch does not exist, not setting tree address"<<endl;
00558   }
00559 
00560   //create the TClonesArrays
00561   fTrkHitInfo=new TClonesArray("CDTrackedHitInfo",1000);
00562   fUnTrkHitInfo=new TClonesArray("CDTrackedHitInfo",1000);
00563   fXTalkHits=new TClonesArray("CDXTalkHitInfo",1000);
00564 
00565   //set the branches to point to the tclonesarrays
00566   fTrackerTree->SetBranchAddress("StraightTrackedHitInfo",
00567                                  &fTrkHitInfo);
00568   fTrackerTree->SetBranchAddress("UnTrackedHitInfo",
00569                                  &fUnTrkHitInfo);
00570   fTrackerTree->SetBranchAddress("XTalkHitInfo",&fXTalkHits);
00571 
00572   //check and set truth hit info branch
00573   if (fTrackerTree->GetBranchStatus("TruthHitInfo")){
00574     fTruthHitInfo=new TClonesArray("CDTruthHitInfo",1000);
00575     fTrackerTree->SetBranchAddress("TruthHitInfo",&fTruthHitInfo);
00576   }
00577   else{
00578     MSG("CDAnalysis",Msg::kInfo)
00579       <<"TruthHitInfo branch does not exist"
00580       <<", not setting tree address"<<endl;
00581   }
00582 
00583   //set the number of events in the tree
00584   fEvents=static_cast<Int_t>(fTrackerTree->GetEntries());
00585 
00586   //get the first snarl/event
00587   if (fTrackerTree) fTrackerTree->GetEvent(0); 
00588   MSG("CDAnalysis",Msg::kInfo)
00589     <<"First snarl="<<fSnarl<<" (sec="<<fSec<<")"<<endl;
00590 
00591   //this is a really ugly, ugly, ugly place to do this...
00592   Calibrator& cal=Calibrator::Instance();  
00593   if (fRunNumber>=70000 && fRunNumber<80000){
00594     cout<<"Setting DriftCalibrator=PulserDriftCalScheme"<<endl;
00595     cal.Set("DriftCalibrator=PulserDriftCalScheme");
00596     cal.GetDriftCalibrator().Set("VATemperatureCalibration=on");
00597     cal.PrintConfig(cout);
00598   }
00599   else{//no tables for 2002 for using PulserDriftCalScheme
00600     cout<<"Setting DriftCalibrator=PulserSigLinCalScheme"<<endl;
00601     cal.Set("DriftCalibrator=PulserSigLinCalScheme");
00602     cal.GetDriftCalibrator().Set("VATemperatureCalibration=on");
00603     cal.PrintConfig(cout);
00604   }
00605 
00606   MSG("CDAnalysis",Msg::kDebug)
00607       <<"Finished the SetRootFileObjects method"<<endl;
00608 }
00609 //......................................................................
00610 
00611 Int_t CDAnalysis::RunNumber2RunPeriod(Int_t run) const
00612 {
00613   //Key to Run Periods (as defined by CBS)
00614   //1   T11 2002 Near-Far        (30000s)
00615   //2   T11 2002 Far-Far         (40000s)
00616   //3   T11 2002 Far-Far   15deg (late 40000s)
00617   //4   T7  2002 Far-Far         (50000s)
00618   //5   T7  2003 Near-Far        (70000s)
00619   //6   T7  2003 Near Only 3m    (80000s)
00620   //7   T7  2003 Near Only 1m    (90000s)
00621   //8   T11 2003 Near Only norm  (100000s)
00622   //9   T11 2003 Near Only 45deg (101000s)
00623   //10  T11 2003 Near Only 30deg (late 101000s)
00624   //11  T11 2003 Near Only 15deg (102000s)
00625 
00626   Int_t runPeriod=0;
00627   if (run>=30000 && run<40000){
00628     runPeriod=1;
00629   }
00630   if (run>=40000 && run<50000){
00631     runPeriod=2;
00632   }
00633   else if (run>=50000 && run<60000){
00634     runPeriod=4;
00635   }
00636   else if (run>=60000 && run<70000){
00637     runPeriod=-1;//this is not defined
00638   }
00639   else if (run>=70000 && run<80000){
00640     runPeriod=5;
00641   }
00642   else if (run>=80000 && run<90000){
00643     runPeriod=6;
00644   }
00645   else if (run>=90000 && run<100000){
00646     runPeriod=7;
00647   }
00648   else if (run>=100000 && run<101000){
00649     runPeriod=8;
00650   }
00651   else if (run>=101000 && run<102000){
00652     runPeriod=9;//or 10, need run number
00653   }
00654   else if (run>=102000 && run<120000){
00655     runPeriod=11;
00656   }
00657   
00658   return runPeriod;
00659 }
00660 
00661 //......................................................................
00662 
00663 void CDAnalysis::SetSigCorPerMEU()
00664 {
00665   if (fSimFlag==SimFlag::kData){
00666     if (fRunNumber>70000 && fRunNumber<80000){
00667       fSigCorPerMEU=591.6;
00668     }
00669     else if (fRunNumber==100161){
00670       fSigCorPerMEU=377.2;
00671     }
00672     else{
00673       MSG("CDAnalysis",Msg::kWarning) 
00674         <<"no run number for sigcor per meu"<<endl;
00675     }
00676   }
00677   else if(fSimFlag==SimFlag::kMC){
00678     fSigCorPerMEU=667.104;
00679   }
00680   else{
00681     MSG("CDAnalysis",Msg::kWarning) 
00682       <<"SetSigCorPerMEU: SimFlag not set"<<endl;
00683   }
00684 
00685   MSG("CDAnalysis",Msg::kInfo) 
00686     <<"Using sigcor per MEU="<<fSigCorPerMEU<<endl;
00687 }
00688 
00689 //......................................................................
00690 
00691 void CDAnalysis::SetScEnDepPerMEU()
00692 {
00693   //using same selection of tracks as in data
00694   fScEnDepPerMEU=0.00195253*Munits::gigaelectronvolt;//new MK dEdx
00695   //fScEnDepPerMEU=0.00194761*Munits::gigaelectronvolt;//new MK dEdx
00696   //fScEnDepPerMEU=0.0296718*Munits::gigaelectronvolt;//orig number
00697 
00698   MSG("CDAnalysis",Msg::kInfo) 
00699     <<"Using ScEnDep per MEU="<<fScEnDepPerMEU<<endl;
00700 }
00701 
00702 //......................................................................
00703 
00704 void CDAnalysis::SetRatioScEnToBeamEn()
00705 {
00706   //using same selection of tracks as in data
00707   fRatioScEnToBeamEn=0.056064;//with new MK dEdx
00708   //fRatioScEnToBeamEn=0.0559147;//with new MK dEdx
00709   //fRatioScEnToBeamEn=0.05638;//orig number
00710   
00711   MSG("CDAnalysis",Msg::kInfo) 
00712     <<"Using Ratio ScEn/BeamEn="<<fRatioScEnToBeamEn<<endl;
00713 }
00714 
00715 //......................................................................
00716 
00717 TFile* CDAnalysis::OpenFile(Int_t runNumber,std::string prefix)
00718 {
00719   //create the tfile pointer to be returned
00720   TFile* outputFile=0;
00721   
00722   //get the environmental variable
00723   char *anaDir=getenv("CDANA_DIR");
00724   
00725   //use a string to hold env instead 
00726   string sAnaDir="";
00727   
00728   if (anaDir!=NULL) {
00729     sAnaDir=anaDir;
00730   }
00731   else {
00732     MSG("CDAnalysis",Msg::kInfo) 
00733       <<"Environmental variable $CDANA_DIR not set." 
00734       <<" Writing file(s) to current directory"<<endl;
00735     sAnaDir=".";
00736   }
00737   
00738   //convert variables to string
00739   string sRunNumber=Form("%d",runNumber);
00740   string sDetector="C";
00741   string sPrefix="h";//default
00742   if (prefix!="") sPrefix+=prefix;
00743   //start all filenames with an h
00744   string sBase=sAnaDir+"/"+sPrefix+sDetector+sRunNumber;
00745   string sFileName=sBase+".root";
00746   
00747   //test if file already exists
00748   ifstream Test(sFileName.c_str());
00749   
00750   //open the appropriate file
00751   if(!Test){
00752     outputFile=new TFile(sFileName.c_str(),"RECREATE");
00753   }
00754   else {
00755     //Need new filename
00756     Int_t fred=1;
00757     while(Test) {
00758       Test.close();
00759       string sAppendage=Form("%d",fred);
00760       sFileName=sBase+"_"+sAppendage+".root";
00761       Test.open(sFileName.c_str());
00762       fred++;
00763     }
00764     outputFile=new TFile(sFileName.c_str(),"NEW");
00765     outputFile->SetCompressionLevel(9);
00766   }
00767   
00768   string sTmp="No File!";
00769   if (outputFile) sTmp=outputFile->GetName();
00770 
00771   MSG("CDAnalysis",Msg::kInfo) 
00772     <<"Output file opened: "<<sTmp<<endl;
00773   return outputFile;
00774 }
00775 
00776 //......................................................................
00777 
00778 ofstream* CDAnalysis::OpenTxtFile(Int_t runNumber,std::string prefix)
00779 {
00780   //create the tfile pointer to be returned
00781   ofstream* outputFile=0;
00782   
00783   //convert variables to string
00784   string sRunNumber=Form("%d",runNumber);
00785   string sDetector="C";
00786   string sPrefix="";//default
00787   string sAnaDir=".";
00788   if (prefix!="") sPrefix+=prefix;
00789   string sBase=sAnaDir+"/"+sPrefix+sDetector+sRunNumber;
00790   string sFileName=sBase+".txt";
00791 
00792   outputFile=new ofstream(sFileName.c_str());
00793   
00794   if (outputFile){
00795     MSG("CDAnalysis",Msg::kInfo) 
00796       <<"Output txt file opened: "<<sFileName<<endl;
00797   }
00798   else{
00799     MSG("CDAnalysis",Msg::kInfo)
00800       <<"Txt file NOT opened: "<<sFileName<<endl;
00801   }
00802 
00803   return outputFile;
00804 }
00805 
00806 //......................................................................
00807 
00808 TGraph* CDAnalysis::TGraphVect(const std::vector<Double_t>& vX,
00809                                const std::vector<Double_t>& vY) const
00810 {
00811   MSG("CDAnalysis",Msg::kDebug) 
00812     <<" ** Running TGraphVect method... **"<<endl;
00813 
00814   TGraph* g=new TGraph(vX.size());
00815 
00816   for (UInt_t i=0;i<vX.size();i++){
00817     g->SetPoint(i,vX[i],vY[i]);
00818   }
00819 
00820   MSG("CDAnalysis",Msg::kDebug) 
00821     <<" ** Finished TGraphVect method **"<<endl;
00822   return g;
00823 }
00824 //......................................................................
00825 
00826 void CDAnalysis::TGraphMinMax(vector<TGraph*>& v) const
00827 {
00828   Float_t max=-1e200;
00829   Float_t min=+1e200;
00830 
00831   for (vector<TGraph*>::iterator vIt=v.begin();vIt!=v.end();++vIt){
00832     for (Int_t i=0;i<(*vIt)->GetN();i++){
00833       Double_t x=0;
00834       Double_t y=0;
00835       (*vIt)->GetPoint(i,x,y);
00836 
00837       //find the min and max
00838       if (y>max) max=y;
00839       if (y<min) min=y;
00840     }
00841   }
00842 
00843   MSG("CDAnalysis",Msg::kDebug)
00844     <<"Found min="<<min<<", max="<<max<<endl;
00845 
00846   //now set the min and max for 10% above and below size of range
00847   for (vector<TGraph*>::iterator vIt=v.begin();vIt!=v.end();++vIt){
00848     (*vIt)->SetMinimum(min-0.1*(max-min));
00849     (*vIt)->SetMaximum(max+0.1*(max-min));
00850   }
00851 }
00852 
00853 //......................................................................
00854 
00855 TGraph* CDAnalysis::TGraphMap(const std::map<Int_t,Float_t>& m) const
00856 {
00857   MSG("CDAnalysis",Msg::kDebug) 
00858     <<" ** Running TGraphMap method... **"<<endl;
00859 
00860   TGraph* g=new TGraph(m.size());
00861 
00862   map<Int_t,Float_t>::const_iterator mIter=m.begin();
00863 
00864   Int_t i=0;
00865 
00866   while (mIter!=m.end()){
00867     g->SetPoint(i,mIter->first,mIter->second);
00868 
00869     i++;
00870     mIter++;
00871   }
00872 
00873   MSG("CDAnalysis",Msg::kDebug) 
00874     <<" ** Finished TGraphMap method **"<<endl;
00875   return g;
00876 }
00877 
00878 //......................................................................
00879 
00880 Int_t CDAnalysis::SumMapValues(const std::map<Int_t,Int_t>& mapIn) const
00881 {
00882   Int_t sum=0;
00883   
00884   //loop and sum the values stored in the map
00885   for (map<Int_t,Int_t>::const_iterator it=mapIn.begin();
00886        it!=mapIn.end();++it){
00887     sum+=it->second;
00888   }
00889   
00890   return sum;
00891 }
00892 
00893 //......................................................................
00894 
00895 void CDAnalysis::NormaliseVector(std::vector<Double_t>& v,
00896                                  Int_t mode) const
00897 {
00898   MSG("CDAnalysis",Msg::kDebug) 
00899     <<" ** Running NormaliseVector method... **"<<endl;
00900   
00901   if (v.size()>0){
00902 
00903     if (mode==1){//simple average
00904       //find average
00905       Double_t average=0;
00906       for (UInt_t i=0;i<v.size();i++) average+=v[i];
00907       average/=v.size();
00908       
00909       MSG("CDAnalysis",Msg::kVerbose)<<"Average="<<average<<endl; 
00910       
00911       //normalise
00912       for (UInt_t i=0;i<v.size();i++) v[i]/=average;
00913     }
00914     else if (mode==2){//fit the function to remove effect of outliers
00915       
00916       Double_t vMax=-9e50;
00917       Double_t vMin=9e50;
00918 
00919       //work out mins and maxs
00920       for (UInt_t i=0;i<v.size();i++){
00921         if (v[i]>vMax) vMax=v[i];
00922         if (v[i]<vMin) vMin=v[i];
00923       }
00924       
00925       //limit the number of bins
00926       Int_t numBins=300;
00927       if (4*v.size()<10000) numBins=4*v.size();
00928 
00929       MSG("LIAnalysis",Msg::kInfo)
00930         <<"vMax="<<vMax <<", vMin="<<vMin<<", numBins="<<numBins<<endl;
00931 
00932       //create the histo
00933       TH1F* h=new TH1F("h","h",numBins,vMin-abs(0.1*vMin),
00934                        vMax+abs(0.1*vMin));
00935       h->SetBit(TH1::kCanRebin);
00936 
00937       Double_t average=0;
00938       for (UInt_t i=0;i<v.size();i++){
00939         //find average
00940         average+=v[i];
00941 
00942         //fill the histo
00943         h->Fill(v[i]);
00944       }
00945       average/=v.size();
00946 
00947       //fit but use 0 (zero!) otherwise it stamps on the current canvas!
00948       h->Fit("gaus","q0");
00949       TF1* func=h->GetFunction("gaus");
00950       Double_t p1=func->GetParameter(1);
00951       Double_t p2=func->GetParameter(2);
00952 
00953       //don't use the fit if it is screwed up
00954       Double_t avToNormWith=p1;
00955       if (p1<vMin || p1>vMax) avToNormWith=average;
00956 
00957       MSG("LIAnalysis",Msg::kInfo)
00958         <<"Fitted mean="<<p1
00959         <<" (average="<<average
00960         <<") fitted rms="<<p2
00961         <<", using avToNormWith="<<avToNormWith<<endl;
00962 
00963       //normalise
00964       for (UInt_t i=0;i<v.size();i++) v[i]/=avToNormWith;
00965 
00966       delete h;
00967     }
00968   }
00969 
00970   MSG("CDAnalysis",Msg::kDebug) 
00971     <<" ** Finished NormaliseVector method **"<<endl;
00972 }
00973 
00974 //......................................................................
00975 
00976 void CDAnalysis::SetLoopVariables(Int_t event)
00977 {
00978   Float_t fract=ceil(fEvents/20.);
00979   
00980   if (ceil(((Float_t)event)/fract)==((Float_t)event)/fract){
00981     MSG("CDAnalysis",Msg::kInfo) 
00982       <<"Fraction of loop complete: "<<event 
00983       <<"/"<<fEvents<<"  ("
00984       <<(Int_t)(100.*event/fEvents)<<"%)"<<endl;
00985   }
00986 
00987   //get the snarl/event
00988   fTrackerTree->GetEvent(event); 
00989 
00990   //initialise snarl level variables
00991   this->InitialiseLoopVariables();
00992 
00993   this->InitialisePidVariables();
00994 
00995   //get the pid info
00996   if (fPIDInfo){
00997     fTriggerPMT=fPIDInfo->GetTriggerPMT();
00998     fFafErr=fPIDInfo->GetFafErr() ;
00999     fSparseErr=fPIDInfo->GetSparseErr();
01000     fTrigSource=fPIDInfo->GetTrigSource();
01001     fKovADC1=fPIDInfo->GetKovADC1() ;
01002     fKovTimeStamp1=fPIDInfo->GetKovTimeStamp1();
01003     fKovADC2=fPIDInfo->GetKovADC2();
01004     fKovTimeStamp2=fPIDInfo->GetKovTimeStamp2();
01005     fKovADC3=fPIDInfo->GetKovADC3();
01006     fKovTimeStamp3=fPIDInfo->GetKovTimeStamp3(); 
01007     fSnarlTimeFrame=fPIDInfo->GetSnarlTimeFrame();
01008     fSnarlMinTimeStamp=fPIDInfo->GetSnarlMinTimeStamp();
01009     fSnarlMaxTimeStamp=fPIDInfo->GetSnarlMaxTimeStamp();
01010     fTofTDC0=fPIDInfo->GetTofTDC0();//actual time of flight
01011     fTofTDC1=fPIDInfo->GetTofTDC1();
01012     fTofTDC2=fPIDInfo->GetTofTDC2();
01013     fTofADC0=fPIDInfo->GetTofADC0();
01014     fTofADC1=fPIDInfo->GetTofADC1();
01015     fTofADC2=fPIDInfo->GetTofADC2();
01016     /*
01017       kTofADCChannel0=ph.GetSpecialChannelContains("TADC0");
01018       kTofADCChannel1=ph.GetSpecialChannelContains("TTAG");
01019       if(kTofADCChannel1==0){
01020          kTofADCChannel1=ph.GetSpecialChannelContains("TADC1");
01021       }
01022       kTofADCChannel2=ph.GetSpecialChannelContains("TimingFid");
01023       if(kTofADCChannel2==0){
01024          kTofADCChannel2=ph.GetSpecialChannelContains("TADC2");
01025       }
01026       kTofTimeStampChannel=ph.GetSpecialChannelContains("TTIME");
01027     */
01028     fTofADCTimeStamp0=fPIDInfo->GetTofADCTimeStamp0();//TADC0
01029     fTofADCTimeStamp1=fPIDInfo->GetTofADCTimeStamp1();//TTAG || TADC1
01030     fTofADCTimeStamp2=fPIDInfo->GetTofADCTimeStamp2();//TimingFid |TADC2
01031     //TofTimeStamp=fPIDInfo->GetTofTimeStamp();//don't use
01032     fTickSinceLast=fPIDInfo->GetTickSinceLast();
01033     
01034     //these are the PID variables
01035     fNoOverlap=fPIDInfo->GetNoOverlap();
01036     fInCERTime=fPIDInfo->GetInCERTime();
01037     fPIDType=fPIDInfo->GetPIDType();
01038     fNoOverlapBits=fPIDInfo->GetNoOverlapBits();
01039     fInCERTimeBits=fPIDInfo->GetInCERTimeBits();
01040     fOLChi2=fPIDInfo->GetOLChi2();
01041   }
01042 }  
01043 
01044 //......................................................................
01045 
01046 void CDAnalysis::PrintBasicInfo(std::string s) const
01047 {
01048   MSG("CDAnalysis",Msg::kInfo)
01049     <<s<<"(Pl,St,End)=("<<fPlane<<","<<fStrip<<","<<fStripend<<")"
01050     <<", adc="<<fChargeAdc
01051     <<", sigL="<<fChargeSigLin
01052     <<", sigC="<<fChargeSigCor
01053     <<", mip="<<fChargeMip
01054     <<", pe="<<fChargePe
01055     <<endl;
01056 }
01057 
01058 //......................................................................
01059 
01060 void CDAnalysis::PrintEvent(Int_t event)
01061 {
01062   if (event>=fEvents) {
01063     MSG("CDAnalysis",Msg::kFatal)
01064       <<"No such event in tree="<<event<<", fEvents="<<fEvents<<endl;
01065     return;
01066   }
01067 
01068   MSG("CDAnalysis",Msg::kInfo)
01069     <<"Printing for event="<<event<<", fEvents="<<fEvents<<endl;
01070 
01071   //get the snarl/event
01072   fTrackerTree->GetEvent(event); 
01073 
01074   //get tclones arrays for this snarl
01075   TClonesArray &cTrk=*fTrkHitInfo;
01076   Int_t numTrkHits=fTrkHitInfo->GetEntries();
01077   TClonesArray &cUnTrk = *fUnTrkHitInfo;
01078   Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
01079   TClonesArray &cXTalk = *fXTalkHits;
01080   Int_t numXTalkHits=fXTalkHits->GetEntries();
01081   
01083   //loop over the untracked hits in the snarl
01085   MSG("CDAnalysis",Msg::kInfo)<<"Untracked hits..."<<endl;
01086   for (Int_t hit=0;hit<numUnTrkHits;hit++){
01087     //cast the tclonesarray up to a trackedhitinfo object
01088     CDTrackedHitInfo *hitInfo=
01089       dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
01090     
01091     this->ReadInHitInfo(hitInfo);
01092     
01093     this->PrintBasicInfo();
01094   }
01095   
01097   //loop over xtalk hits in the snarl
01099   MSG("CDAnalysis",Msg::kInfo)<<"XTalk hits..."<<endl;
01100   for (Int_t hit=0;hit<numXTalkHits;hit++){
01101     CDXTalkHitInfo *hitInfo=
01102       dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
01103     
01104     this->ReadInHitInfo(hitInfo);
01105 
01106     this->PrintBasicInfo();
01107   }
01108 
01110   //loop over the tracked hits
01112   MSG("CDAnalysis",Msg::kInfo)<<"Tracked hits..."<<endl;
01113   for (Int_t hit=0;hit<numTrkHits;hit++){
01114     CDTrackedHitInfo* hitInfo=
01115       dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
01116 
01117     this->ReadInHitInfo(hitInfo);
01118     
01119     this->PrintBasicInfo();
01120   }
01121 }
01122 
01123 //......................................................................
01124 
01125 void CDAnalysis::CalcNumPlanesHit(Int_t plane,Float_t pe)
01126 {
01127   //calc the num planes hit
01128   fNumPlanesHitAll[plane]++;
01129 
01130   //calc number of planes hit in first 25
01131   if (plane<25) fNumPlanesHit25[plane]++;
01132 
01133   //calc if pe cut satisfied
01134   if (pe>1.5) {
01135     fNumPlanesHitPeCut[plane]++;
01136 
01137     //only calc planes hit in first 10 planes
01138     if (plane<10) fNumPlanesHitPeCut10[plane]++;
01139   }
01140 }
01141 
01142 //......................................................................
01143 
01144 void CDAnalysis::CalcNumPlanesHitTrk(Int_t plane)
01145 {
01146   //calc the num planes hit
01147   fNumPlanesHitTrk[plane]++;
01148 }
01149 
01150 //......................................................................
01151 
01152 void CDAnalysis::CalcAvStripForPSMuonCut(Int_t plane,Int_t strip,
01153                                          Int_t end)
01154 {
01155   if (plane<4){
01156     //calc weighted average strip
01157     fAvStrip=fAvStrip*(fStCount/(fStCount+1))+strip*(1/(fStCount+1));
01158     fStCount++;
01159     MAXMSG("CDAnalysis",Msg::kVerbose,1000)
01160       <<"  strip="<<strip<<", plane="<<plane
01161       <<", fEnd="<<fStripend<<", fAvStrip="<<fAvStrip
01162       <<", fStCount="<<fStCount<<endl;
01163 
01164     //now do each end separately
01165     if (end==1 && plane>0) {
01166       fAvStrip1=fAvStrip1*(fStCount1/(fStCount1+1))+
01167         strip*(1/(fStCount1+1));
01168       fStCount1++;
01169     }
01170     else if (end==2 && plane>0) {
01171       fAvStrip2=fAvStrip2*(fStCount2/(fStCount2+1))+
01172         strip*(1/(fStCount2+1));
01173       fStCount2++;
01174     }
01175   }
01176 }
01177 
01178 //......................................................................
01179 
01180 void CDAnalysis::CalcLowUpScint_TofDiff(Double_t time)
01181 {
01182   Double_t tickInNs=25./16;//ns, va clock tick
01183   Float_t timeDiff=(time*1e9)-(fTofADCTimeStamp1*tickInNs);//ns
01184 
01185   if (fTofADCTimeStamp1<1 || fTofADCTimeStamp1>1e9/tickInNs){
01186     MAXMSG("CDAnalysis",Msg::kWarning,10)
01187       <<"Bad Tof (TTAG) time="<<fTofADCTimeStamp1
01188       <<" ticks, ("<<fTofADCTimeStamp1*tickInNs<<" ns)"<<endl;
01189   }
01190 
01191   if (timeDiff>1000 || timeDiff<-1000){
01192     MAXMSG("CDAnalysis",Msg::kWarning,10)
01193       <<"Bad Scint-Tof (TTAG) time difference="<<timeDiff<<" ns"
01194       <<", time="<<time<<", tof time="<<fTofADCTimeStamp1
01195       <<" ticks, ("<<fTofADCTimeStamp1*tickInNs<<" ns)"<<endl;
01196   }
01197 
01198   //calc highest and lowest scint tof time diff.
01199   if (timeDiff>fUpScint_Tof) fUpScint_Tof=timeDiff;
01200   if (timeDiff<fLowScint_Tof) fLowScint_Tof=timeDiff;
01201 }
01202 
01203 //......................................................................
01204 
01205 void CDAnalysis::CalcFirstLastPlane(Int_t plane)
01206 {
01207   if (plane<fFirstPlane) fFirstPlane=plane;
01208   if (plane>fLastPlane) fLastPlane=plane;
01209   if (plane>fLastPlaneOdd && plane%2!=0) fLastPlaneOdd=plane;
01210   if (plane>fLastPlaneEven && plane%2==0) fLastPlaneEven=plane;
01211 }
01212 
01213 //......................................................................
01214 
01215 Int_t CDAnalysis::CalcLastPlaneTruth() const
01216 {  
01217   if (!fTruthHitInfo) return 0;
01218 
01219   TClonesArray &cTruth = *fTruthHitInfo;
01220   Int_t numTruthHits=fTruthHitInfo->GetEntries();
01221 
01222   Int_t lastPlane=0;
01223 
01224   //loop over the truth hits
01225   for (Int_t hit=0;hit<numTruthHits;hit++){
01226     //cast the tclonesarray up to a truthhitinfo object
01227     CDTruthHitInfo *hitInfo=
01228       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
01229     
01230     Int_t plane=hitInfo->GetPlane();
01231     Int_t pmtTruth1=hitInfo->GetPmtTruth1();
01232     Int_t pmtTruth2=hitInfo->GetPmtTruth2();
01233 
01234     //check either side
01235     Int_t sumTruth=pmtTruth1|pmtTruth2;
01236 
01237     //check if genuine
01238     if ((sumTruth & DigiSignal::kGenuine)==DigiSignal::kGenuine){
01239       //see if bigger
01240       if (plane>lastPlane) lastPlane=plane;
01241     }
01242     MSG("CDAnalysis",Msg::kVerbose)
01243       <<"sumTruth="<<sumTruth<<endl;
01244   }
01245 
01246   MSG("CDAnalysis",Msg::kVerbose)
01247     <<"CalcLastPlaneTruth: LastPlane="<<lastPlane
01248     <<", fLastPlane="<<fLastPlane<<endl; 
01249 
01250   return lastPlane;
01251 }
01252 
01253 //......................................................................
01254 
01255 void CDAnalysis::CalcLastPlaneOnTrk()
01256 {
01257 
01258   TClonesArray &cTrk=*fTrkHitInfo;
01259   Int_t numTrkHits=fTrkHitInfo->GetEntries();
01260 
01262   //loop over the tracked hits
01264   for (Int_t hit=0;hit<numTrkHits;hit++){
01265     CDTrackedHitInfo *trackedHitInfo=
01266       dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
01267     
01268     this->ReadInHitInfo(trackedHitInfo);
01269     
01270     //cut out the bad channels
01271     if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
01272     
01273     //check the channel's sanity
01274     this->StandardSanityChecks();
01275     
01276     //calculate the first and last planes
01277     this->CalcFirstLastPlane(fPlane);
01278     
01279   }
01281   //end of loop over the tracked hits
01283   
01284   MSG("CDAnalysis",Msg::kVerbose)
01285     <<"CalcLastPlaneOnTrk: fLastPlane="<<fLastPlane<<endl; 
01286 }
01287 
01288 //......................................................................
01289 
01290 Int_t CDAnalysis::CalcLastPlaneOnTrkNoXTalk() const
01291 {
01292   //get tclones arrays for this snarl
01293   TClonesArray &cTrk=*fTrkHitInfo;
01294   Int_t numTrkHits=fTrkHitInfo->GetEntries();
01295   TClonesArray &cUnTrk = *fUnTrkHitInfo;
01296   Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
01297   TClonesArray &cXTalk = *fXTalkHits;
01298   Int_t numXTalkHits=fXTalkHits->GetEntries();
01299   
01300   map<Int_t,Float_t> planeGreatestPe;
01301   Int_t lastPlane=0;  
01302 
01303   //the untracked and xtalk hits are just used to find the greatest
01304   //pe in each plane; they are not included in the last plane 
01305   //directly
01306 
01308   //loop over the untracked hits in the snarl
01310   for (Int_t hit=0;hit<numUnTrkHits;hit++){
01311     //cast the tclonesarray up to a trackedhitinfo object
01312     CDTrackedHitInfo *hitInfo=
01313       dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
01314     
01315     //get the variables
01316     Int_t plane=hitInfo->GetPlane();
01317     Int_t strip=hitInfo->GetStrip();
01318     Int_t stripend=hitInfo->GetEnd();
01319     Float_t chargePe=hitInfo->GetCharge(CDTrackedHitInfo::kPe);
01320 
01321     //cut out the bad channels
01322     if (this->CutOnBadPedestals(plane,strip,stripend)) continue;
01323     
01324     if (chargePe>planeGreatestPe[fPlane]) planeGreatestPe[plane]=
01325                                             chargePe;
01326   }
01327   
01329   //loop over xtalk hits in the snarl
01331   for (Int_t hit=0;hit<numXTalkHits;hit++){
01332     CDXTalkHitInfo *hitInfo=
01333       dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
01334     
01335     //get the variables
01336     Int_t plane=hitInfo->GetPlane();
01337     Int_t strip=hitInfo->GetStrip();
01338     Int_t stripend=hitInfo->GetEnd();
01339     Float_t chargePe=hitInfo->GetCharge(CDTrackedHitInfo::kPe);
01340 
01341     //cut out the bad channels
01342     if (this->CutOnBadPedestals(plane,strip,stripend)) continue;
01343     
01344     if (chargePe>planeGreatestPe[fPlane]) planeGreatestPe[plane]=
01345                                             chargePe;
01346   }
01347 
01349   //loop over the tracked hits
01351   for (Int_t hit=0;hit<numTrkHits;hit++){
01352     CDTrackedHitInfo* hitInfo=
01353       dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
01354     
01355     //get the variables
01356     Int_t plane=hitInfo->GetPlane();
01357     Int_t strip=hitInfo->GetStrip();
01358     Int_t stripend=hitInfo->GetEnd();
01359     Float_t chargePe=hitInfo->GetCharge(CDTrackedHitInfo::kPe);
01360 
01361     if (plane>lastPlane) lastPlane=plane;
01362 
01363     //cut out the bad channels
01364     if (this->CutOnBadPedestals(plane,strip,stripend)) continue;
01365     
01366     if (chargePe>planeGreatestPe[fPlane]) planeGreatestPe[plane]=
01367                                             chargePe;
01368   }
01370   //end of loop over the tracked hits
01372 
01373   Int_t newLastPlane=lastPlane;
01374   Double_t xtalkLevel=1.7;
01375 
01376   if (fLastPlane>=3){//make sure track is at least 4 planes
01377     if (planeGreatestPe[lastPlane]>xtalkLevel){
01378       //do nothing
01379     }
01380     else if (planeGreatestPe[lastPlane-1]>xtalkLevel){
01381       newLastPlane=lastPlane-1;
01382     }
01383     else if (planeGreatestPe[lastPlane-2]>xtalkLevel){
01384       newLastPlane=lastPlane-2;
01385     }
01386     else{
01387       if (planeGreatestPe[lastPlane-3]<xtalkLevel){
01388         MSG("CDAnalysis",Msg::kDebug)
01389           <<"4th plane with low pe hit"
01390           <<", pe0="<<planeGreatestPe[lastPlane-0]
01391           <<", pe1="<<planeGreatestPe[lastPlane-1]
01392           <<", pe2="<<planeGreatestPe[lastPlane-2]
01393           <<", pe3="<<planeGreatestPe[lastPlane-3]
01394           <<endl;
01395       }
01396       newLastPlane=lastPlane-3;
01397     }
01398   }
01399   
01400   MSG("CDAnalysis",Msg::kVerbose)
01401     <<"CalcLastPlaneOnTrkNoXTalk: lastPlane="<<lastPlane
01402     <<", newLastPlane="<<newLastPlane<<endl; 
01403   
01404   return newLastPlane;
01405 }
01406 
01407 //......................................................................
01408 
01409 void CDAnalysis::ReadInHitInfo(CDTrackedHitInfo* hitInfo)
01410 {
01411   //initialise variables to be on the safe side
01412   this->InitialiseHitInfoVariables();
01413 
01414   fTime=hitInfo->GetTime();
01415 
01416   //get the variables
01417   fPlane=hitInfo->GetPlane();
01418   fStrip=hitInfo->GetStrip();
01419   fStripend=hitInfo->GetEnd();
01420   fTransPos=hitInfo->GetTransPos();
01421   
01422   //decide which stripend is which; odd, even, 1 or 2.
01423   fO1=(fStripend==1 && fPlane%2==1);
01424   fO2=(fStripend==2 && fPlane%2==1);
01425   fE1=(fStripend==1 && fPlane%2==0);
01426   fE2=(fStripend==2 && fPlane%2==0);
01427 
01428   //look at the calorimetry info
01429   fChargeAdc=hitInfo->GetCharge(CDTrackedHitInfo::kAdc);
01430   fChargeMip=hitInfo->GetCharge(CDTrackedHitInfo::kMip);
01431   fChargeSigCor=hitInfo->GetCharge(CDTrackedHitInfo::kSigCorr);
01432   fChargeSigLin=hitInfo->GetCharge(CDTrackedHitInfo::kSigLin);
01433   fChargePe=hitInfo->GetCharge(CDTrackedHitInfo::kPe);
01434   if (fChargePe!=0) fGain=fChargeSigLin/fChargePe;
01435   else fGain=-1;
01436 
01437   static Bool_t firstTime=true;
01438   if (fChargeMip>0 && fChargeSigCor>0 && firstTime){
01439     firstTime=false;
01440     fSigCorsPerMip=fChargeSigCor/fChargeMip;
01441     MAXMSG("CDAnalysis",Msg::kVerbose,100)
01442       <<"fSigCorsPerMip="<<fSigCorsPerMip<<endl;
01443   }
01444 
01445   //get the tracker evaluation of the event
01446   fResultEven=fTrackInfo->GetResult(0);
01447   fResultOdd=fTrackInfo->GetResult(1);
01448 }
01449 
01450 //......................................................................
01451 
01452 void CDAnalysis::ReadInHitInfo(CDXTalkHitInfo* hitInfo)
01453 {
01454   //initialise variables to be on the safe side
01455   this->InitialiseHitInfoVariables();
01456 
01457   fTime=hitInfo->GetTime();
01458 
01459   //get the variables
01460   fPlane=hitInfo->GetPlane();
01461   fStrip=hitInfo->GetStrip();
01462   fStripend=hitInfo->GetEnd();
01463   //fTransPos=hitInfo->GetTransPos();
01464   fTransPos=-1;//npt possible to calculate for xtalk
01465 
01466   //decide which stripend is which; odd, even, 1 or 2.
01467   fO1=(fStripend==1 && fPlane%2==1);
01468   fO2=(fStripend==2 && fPlane%2==1);
01469   fE1=(fStripend==1 && fPlane%2==0);
01470   fE2=(fStripend==2 && fPlane%2==0);
01471 
01472   //look at the calorimetry info
01473   fChargeAdc=hitInfo->GetCharge(CDTrackedHitInfo::kAdc);
01474   fChargeMip=hitInfo->GetCharge(CDTrackedHitInfo::kMip);
01475   fChargeSigCor=hitInfo->GetCharge(CDTrackedHitInfo::kSigCorr);
01476   fChargeSigLin=hitInfo->GetCharge(CDTrackedHitInfo::kSigLin);
01477   fChargePe=hitInfo->GetCharge(CDTrackedHitInfo::kPe);
01478   if (fChargePe!=0) fGain=fChargeSigLin/fChargePe;
01479   else fGain=-1;
01480 }
01481 
01482 //......................................................................
01483 
01484 Float_t CDAnalysis::CalcPathLengthCorection(const TVector3& end1,
01485                                             const TVector3& end2) const
01486 {
01487   //calc pathlength between two points
01488   Float_t x=end1.X()-end2.X();
01489   Float_t y=end1.Y()-end2.Y();
01490   Float_t z=end1.Z()-end2.Z();
01491   Float_t pathLength=sqrt(pow(x,2)+pow(y,2)+pow(z,2));
01492   //calc path length correction
01493   Float_t pathLengthCor=-1;
01494   if (z!=0) pathLengthCor=pathLength/fabs(z);
01495   else cout<<"pathlength cor problem: z="<<z
01496            <<", x="<<x<<", y="<<y<<endl;
01497   return pathLengthCor;
01498 }
01499 
01500 //......................................................................
01501 
01502 void CDAnalysis::CalcXorYandZ(Int_t strip,Int_t plane,
01503                               Float_t& x,Float_t& y,Float_t& z) const
01504 {
01505   Float_t planePitch=5.94*Munits::cm;
01506   Float_t stripWidth=4.1*Munits::cm;
01507   Float_t stripsFromCentre=strip-11.5;//middle 2 strips 11&12 are 0.5 st
01508   Float_t distFromCentre=stripsFromCentre*stripWidth;
01509   
01510   //calc z
01511   z=plane*planePitch;
01512 
01513   if (plane%2==0){//even, v-view (measure v and y), horizontal strips
01514     x=-1;
01515     y=distFromCentre;
01516   }
01517   else if (plane%2==1){//odd, u-view (measure u and x), vertical strips
01518     x=distFromCentre;;
01519     y=-1;
01520   }
01521 }
01522 
01523 //......................................................................
01524 
01525 void CDAnalysis::TrueHighLowEn(Float_t& highEn,Float_t& lowEn) const
01526 {
01527   if (!fTruthHitInfo) return;
01528 
01529   //initialise
01530   lowEn=999999;
01531   highEn=-1;
01532 
01533   TClonesArray &cTruth = *fTruthHitInfo;
01534   Int_t numTruthHits=fTruthHitInfo->GetEntries();
01535   
01536   //loop over the truth hits
01537   for (Int_t hit=0;hit<numTruthHits;hit++){
01538     //cast the tclonesarray up to a truthhitinfo object
01539     CDTruthHitInfo *hitInfo=
01540       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
01541     
01542     Double_t energy=hitInfo->GetMainPartEn();
01543     Int_t particle=hitInfo->GetMainParticle();
01544     Int_t muon=13;
01545     
01546     if (abs(particle)==muon) {
01547       if (energy>highEn) highEn=energy;
01548       if (energy<lowEn) lowEn=energy; 
01549     }
01550   }
01551 
01552   //reset to -1 if not found to be consistent with highEn
01553   if (lowEn==999999) lowEn=-1;
01554 }
01555 
01556 //......................................................................
01557 
01558 void CDAnalysis::TruePLCor(std::map<Int_t,Float_t>& mPLCor,
01559                            Int_t event) const
01560 {
01561   Int_t lastPlane=this->GetEventLength();
01562   if (lastPlane<0) return;
01563   Float_t lastPLCor=-1;
01564   Float_t lastPL=-1;
01565 
01566   for (Int_t pl=0;pl<=lastPlane;pl++){
01567     Float_t pathLen=this->TrueMainPL(pl,event);
01568     //get a zero if no dsh in a plane
01569     //also know that PL must be at least 0.95 cm
01570     if (pathLen<0.95*Munits::cm) {
01571       if (lastPL>=0.95*Munits::cm) pathLen=lastPL;
01572       else pathLen=0.95*Munits::cm;
01573     }
01574     //record the last PL
01575     lastPL=pathLen;
01576 
01577     Float_t pathLengthCor=pathLen/(0.95*Munits::cm);
01578     if (pathLengthCor<0.999) {
01579       MAXMSG("CDAnalysis",Msg::kWarning,500)
01580         <<"bad PLCor="<<pathLengthCor<<endl;
01581       if (lastPLCor>=1) pathLengthCor=lastPLCor;
01582       else pathLengthCor=1;
01583     }
01584     else if (pathLengthCor>0.999 && pathLengthCor<1){
01585       MAXMSG("CDAnalysis",Msg::kVerbose,500)
01586         <<"fractionally wrong PLCor="<<pathLengthCor<<endl;
01587       pathLengthCor=1;
01588     }
01589 
01590     //insert the value into the map
01591     mPLCor[pl]=pathLengthCor;
01592 
01593     //record the last PLCor
01594     lastPLCor=pathLengthCor;
01595   }
01596 }
01597 
01598 //......................................................................
01599 
01600 Bool_t CDAnalysis::CalcPLCor(const std::map<Int_t,TVector3>& mPlPos,
01601                              std::map<Int_t,Float_t>& mPLCor) const
01602 {
01603   map<Int_t,TVector3>::const_iterator plPosEndIt=mPlPos.end();
01604 
01605   //Int_t lastPlaneNoXTalk=this->CalcLastPlaneOnTrkNoXTalk();
01606   Int_t lastPlane=this->GetEventLength();
01607   Float_t initValue=-999;
01608  
01609   for (Int_t pl=0;pl<=lastPlane;pl++){
01610     Int_t plVtxSide=pl-2;
01611     Int_t plStopSide=pl+2;
01612     
01613     //protect against going outside allowed ranges
01614     if (plVtxSide<0) plVtxSide=0;
01615     if (plStopSide>lastPlane) plStopSide=lastPlane;
01616 
01617     MAXMSG("CDAnalysis",Msg::kDebug,500)
01618       <<"pl="<<pl<<", plStopSide="<<plStopSide
01619       <<", plVtxSide="<<plVtxSide<<endl;
01620 
01621     //fit track position
01622     TGraph gx_z(3);//min of 3 points
01623     TGraph gy_z(3);
01624     Int_t tmpPl=plStopSide;
01625     Int_t tmpPlVtxSide=plVtxSide+1;
01626     Bool_t posDir=true;//always forward going in caldet
01627     if (posDir) tmpPlVtxSide=plVtxSide-1;
01628     Int_t i=0;
01629     //loop over planes to fit
01630     while (tmpPl!=tmpPlVtxSide){
01631       map<Int_t,TVector3>::const_iterator plPosIt=mPlPos.find(tmpPl);
01632       if (plPosIt!=plPosEndIt){
01633         Float_t x=(plPosIt->second).x();
01634         Float_t y=(plPosIt->second).y();
01635         Float_t z=(plPosIt->second).z();
01636         gx_z.SetPoint(i,z,x);
01637         gy_z.SetPoint(i,z,y);
01638         MAXMSG("CDAnalysis",Msg::kVerbose,500)
01639           <<"Adding point: x="<<x<<", y="<<y<<", z="<<z<<endl;
01640         //count the number of points added
01641         i++;
01642       }
01643       //increment the plane
01644       if (posDir) tmpPl--;
01645       else tmpPl++;
01646     }
01647   
01648     Float_t newPLCor=initValue;
01649     if (i>=3){
01650       gx_z.Fit("pol1","q");
01651       gy_z.Fit("pol1","q");
01652       Float_t mx_z=gx_z.GetFunction("pol1")->GetParameter(1);
01653       Float_t my_z=gy_z.GetFunction("pol1")->GetParameter(1);
01654       //Float_t mx_zErr=gx_z.GetFunction("pol1")->GetParError(1);
01655       //Float_t my_zErr=gy_z.GetFunction("pol1")->GetParError(1);
01656       newPLCor=sqrt(pow(mx_z,2)+pow(my_z,2)+1);
01657       MAXMSG("CDAnalysis",Msg::kDebug,500)
01658         <<"pl="<<pl<<", found plcor="<<newPLCor<<endl;
01659     }
01660     else {
01661       MSG("CDAnalysis",kWarning)
01662         <<"Less than 3 points, can't do local grad. fit"<<endl;
01663       return false;
01664     }
01665 
01666     if (newPLCor!=initValue) mPLCor[pl]=newPLCor;
01667     else MSG("CDAnalysis",kInfo)<<"Bad PLCor"<<endl;
01668 
01669   } 
01670 
01671   return true;
01672 }
01673 
01674 //......................................................................
01675 
01676 Bool_t CDAnalysis::CalcXYZ(std::map<Int_t,TVector3>& mPlPos) const
01677 {
01678   //get tclones arrays for this snarl
01679   TClonesArray &cTrk=*fTrkHitInfo;
01680   Int_t numTrkHits=fTrkHitInfo->GetEntries();
01681   
01682   if (numTrkHits<2){
01683     MAXMSG("CDAnalysis",Msg::kWarning,100)
01684       <<"CalcXYZ::numTrkHits is bad="<<numTrkHits<<endl;
01685     return false;
01686   }
01687 
01688   //Int_t lastPlaneNoXTalk=this->CalcLastPlaneOnTrkNoXTalk();
01689   Int_t lastPlane=this->GetEventLength();
01690   if (lastPlane<2 || lastPlane>59){
01691     MAXMSG("CDAnalysis",Msg::kWarning,100)
01692       <<"CalcXYZ::last plane is bad="<<lastPlane<<endl;
01693     return false;
01694   }
01695 
01696   Bool_t foundFirstFew=false;
01697   Bool_t unFilledGap=false;
01698   Float_t initValue=-999;
01699   vector<TVector3> plPosition(60);
01700   for (Int_t pl=0;pl<60;pl++){
01701     plPosition[pl]=TVector3(initValue,initValue,initValue);
01702   }
01703 
01705   //loop over the tracked hits
01707   for (Int_t hit=0;hit<numTrkHits;hit++){
01708     CDTrackedHitInfo* hitInfo=
01709       dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
01710     
01711     //get the variables
01712     Int_t plane=hitInfo->GetPlane();
01713     Int_t strip=hitInfo->GetStrip();
01714     Int_t stripend=hitInfo->GetEnd();
01715     //Float_t chargePe=hitInfo->GetCharge(CDTrackedHitInfo::kPe);
01716 
01717     //cut out the bad channels
01718     if (this->CutOnBadPedestals(plane,strip,stripend)) continue;
01719 
01720     Float_t x=initValue;
01721     Float_t y=initValue;
01722     Float_t z=initValue;
01723     this->CalcXorYandZ(strip,plane,x,y,z);
01724 
01725     plPosition[plane]=TVector3(x,y,z);
01726 
01727   }
01729   //end of loop over the tracked hits
01731 
01732   //calc the x and y of the first two planes
01733   //loop and look at more planes if can't find any hits in first few
01734   for (Int_t np=2;np<=5;np++){
01735     //look at first few even planes
01736     Float_t yAvFirstFew=0;
01737     Float_t yAvFirstFewCounter=0;
01738     for (Int_t pl=0;pl<np*2;pl+=2){//even measures v or y
01739       if (plPosition[pl].y()!=initValue){
01740         yAvFirstFew+=plPosition[pl].y();
01741         yAvFirstFewCounter++;
01742       }
01743     }
01744     if (yAvFirstFewCounter>0) yAvFirstFew/=yAvFirstFewCounter;
01745     else yAvFirstFew=initValue;
01746     
01747     //look at first few odd planes
01748     Float_t xAvFirstFew=0;
01749     Float_t xAvFirstFewCounter=0;
01750     for (Int_t pl=1;pl<np*2;pl+=2){//odd measures u or x
01751       if (plPosition[pl].x()!=initValue){
01752         xAvFirstFew+=plPosition[pl].x();
01753         xAvFirstFewCounter++;
01754       }
01755     }
01756     if (xAvFirstFewCounter>0) xAvFirstFew/=xAvFirstFewCounter;
01757     else xAvFirstFew=initValue;
01758     
01759     MAXMSG("CDAnalysis",Msg::kDebug,1000)
01760       <<"num planes="<<np
01761       <<", avX="<<xAvFirstFew<<" ("<<xAvFirstFewCounter<<")"
01762       <<", avY="<<yAvFirstFew<<" ("<<yAvFirstFewCounter<<")"<<endl;
01763 
01764     //now set the TVectors if an average was obtained
01765     if (xAvFirstFew==initValue || yAvFirstFew==initValue){
01766       MAXMSG("CDAnalysis",Msg::kVerbose,100)
01767         <<endl<<"Not found tracked hits with num planes="<<np
01768         <<", looping again..."<<endl<<endl;
01769     }
01770     else{
01771       //set the first 2 planes (what is not measured by that plane)
01772       plPosition[0].SetX(xAvFirstFew);
01773       plPosition[1].SetY(yAvFirstFew);
01774       
01775       //sometimes have to set what should have been measured if 
01776       //it is missing
01777       if (plPosition[0].Y()==initValue || plPosition[1].X()==initValue){
01778         MAXMSG("CDAnalysis",Msg::kDebug,100)
01779           <<endl<<"Having to manually set x or y in first few planes"
01780           <<endl<<endl;
01781         //plPosition[0].Print();
01782         //plPosition[1].Print();
01783       }
01784       if (plPosition[0].Y()==initValue) plPosition[0].SetY(yAvFirstFew);
01785       if (plPosition[1].X()==initValue) plPosition[1].SetX(xAvFirstFew);
01786       foundFirstFew=true;
01787       break;
01788     }
01789   }
01790 
01791   if (!foundFirstFew){
01792     MAXMSG("CDAnalysis",Msg::kDebug,100)
01793       <<endl<<"Not found hits in first few planes ignoring this event"
01794       <<endl<<endl;
01795     return false;
01796   }
01797 
01798   //probably best to do the +/- 2 planes first to fill the gaps
01799   //then do the interpolation into the planes that don't measure
01800   //what is needed.
01801 
01803   //loop and fill the gaps
01805   for (Int_t pl=2;pl<=lastPlane;pl++){
01806 
01807     Bool_t foundGap=false;
01808     
01809     //check for gaps
01810     if (pl%2==0){//even planes, measures v and y
01811       if (plPosition[pl].Y()==initValue) foundGap=true;
01812     }
01813     else if (pl%2==1){//odd planes, measures u and x
01814       if (plPosition[pl].X()==initValue) foundGap=true;
01815     }
01816 
01817     if (foundGap) {
01818       Int_t plPrev=pl-2;
01819       Int_t plNext=pl+2;
01820       Int_t plPrev4=pl-4;
01821       Int_t plNext4=pl+4;
01822       Float_t posPrev=initValue;
01823       Float_t posNext=initValue;
01824       Float_t pos=initValue;
01825       Float_t posPrev4=initValue;
01826       Float_t posNext4=initValue;
01827       Float_t pos4=initValue;
01828 
01829       //protect against going outside allowed ranges
01830       if (plPrev<0) {
01831         if (abs(plPrev%2)==0) plPrev=0;//even
01832         else if (abs(plPrev%2)==1) plPrev=1;//odd
01833       }
01834       if (plNext>59){
01835         if (plNext%2==0) plNext=58;//even
01836         else if (plNext%2==1) plNext=59;//odd
01837       }
01838       if (plPrev4<0) {
01839         if (abs(plPrev4%2)==0) plPrev4=0;//even
01840         else if (abs(plPrev4%2)==1) plPrev4=1;//odd
01841       }
01842       if (plNext4>59){
01843         if (plNext4%2==0) plNext4=58;//even
01844         else if (plNext4%2==1) plNext4=59;//odd
01845       }
01846       
01847       if (pl%2==0){//even planes, measures v and y
01848         //get position
01849         posPrev=plPosition[plPrev].Y();
01850         posNext=plPosition[plNext].Y();
01851         posPrev4=plPosition[plPrev4].Y();
01852         posNext4=plPosition[plNext4].Y();
01853       }
01854       else if (pl%2==1){//odd planes, measures u and x
01855         //get position
01856         posPrev=plPosition[plPrev].X();
01857         posNext=plPosition[plNext].X();
01858         posPrev4=plPosition[plPrev4].X();
01859         posNext4=plPosition[plNext4].X();
01860       }
01861       
01862       if (posPrev==initValue || posNext==initValue){
01863         MAXMSG("CDAnalysis",Msg::kDebug,500)
01864           <<"pl="<<pl<<", not found position"
01865           <<", prev="<<posPrev<<", next="<<posNext
01866           <<endl;
01867       }
01868       else{
01869         //calc the new position
01870         pos=(posPrev+posNext)*0.5;
01871         //MAXMSG("CDAnalysis",Msg::kDebug,1000)
01872         //<<"pl="<<pl
01873         //<<", found positions, prev="<<posPrev<<", next="<<posNext
01874         //<<", pos="<<pos<<endl;
01875       }
01876 
01877       if (posPrev4==initValue || posNext4==initValue){
01878         MAXMSG("CDAnalysis",Msg::kDebug,500)
01879           <<"pl="<<pl<<", not found position"
01880           <<", prev4="<<posPrev4<<", next4="<<posNext
01881           <<endl;
01882       }
01883       else{
01884         //calc the new position
01885         pos4=(posPrev4+posNext4)*0.5;
01886         //MAXMSG("CDAnalysis",Msg::kDebug,1000)
01887         //<<"pl="<<pl
01888         //<<", found positions, prev4="<<posPrev4<<", next4="<<posNext4
01889         //<<", pos4="<<pos4<<endl;
01890       }
01891     
01892       Float_t posToUse=pos;
01893       if (posToUse==initValue) posToUse=pos4;
01894 
01895       if (posToUse!=initValue){
01896         if (pl%2==0){//even planes, measures v and y
01897           //set position
01898           //MAXMSG("CDAnalysis",Msg::kDebug,1000)
01899           //<<"pl="<<pl<<", setting pos="<<posToUse
01900           //<<", y was="<<plPosition[pl].Y()<<endl;
01901           plPosition[pl].SetY(posToUse);
01902         }
01903         else if (pl%2==1){//odd planes, measures u and x
01904           //set position
01905           //MAXMSG("CDAnalysis",Msg::kDebug,1000)
01906           //<<"pl="<<pl<<", setting pos="<<posToUse
01907           //<<", x was="<<plPosition[pl].X()<<endl;
01908           plPosition[pl].SetX(posToUse);
01909         }
01910       }
01911       else{
01912         MAXMSG("CDAnalysis",Msg::kDebug,3000)
01913           <<"pl="<<pl<<", fLastPlane="<<fLastPlane
01914           <<", lastPl="<<lastPlane
01915           <<", not managed to fill gap with first method"<<endl;
01916         unFilledGap=true;
01917       }
01918     }
01919     else{
01920       MAXMSG("CDAnalysis",Msg::kDebug,3000)
01921         <<"pl="<<pl<<", no gap"<<endl;
01922     }
01923   }
01924 
01925   //fill any gaps that failed to get filled above
01926   //simple algorithm to just use the previous x/y value in the track
01927   Float_t lastX=initValue;
01928   Float_t lastY=initValue;
01929   if (unFilledGap){
01930     for (Int_t pl=0;pl<=lastPlane;pl++){
01931       if (pl%2==0){//even planes, measures v and y
01932         if (plPosition[pl].Y()==initValue){
01933           plPosition[pl].SetY(lastY);
01934           //MAXMSG("CDAnalysis",Msg::kVerbose,1000)
01935           //<<"pl="<<pl<<", fLastPlane="<<fLastPlane
01936           //<<", lastPl="<<lastPlane
01937           //<<", filled gap (y="<<lastY<<")"<<endl;
01938         }
01939         //get last position in track
01940         lastY=plPosition[pl].Y();
01941       }
01942       else if (pl%2==1){//odd planes, measures u and x
01943         if (plPosition[pl].X()==initValue){
01944           plPosition[pl].SetX(lastX);
01945           //MAXMSG("CDAnalysis",Msg::kVerbose,1000)
01946           //<<"pl="<<pl<<", fLastPlane="<<fLastPlane
01947           //<<", lastPl="<<lastPlane
01948           //<<", filled gap (x="<<lastX<<")"<<endl;
01949         }
01950         //get last position in track
01951         lastX=plPosition[pl].X();
01952       }
01953     }
01954   }
01955   
01957   //loop and just do the simple calculations 
01958   //+/- 1 plane to calc what is not measured
01960   for (Int_t pl=2;pl<=lastPlane;pl++){
01961     Int_t plPrev=pl-1;
01962     Int_t plNext=pl+1;
01963     Float_t posPrev=initValue;
01964     Float_t posNext=initValue;
01965     Float_t pos=initValue;
01966     
01967     //protect against going outside allowed ranges
01968     if (plPrev<0) {
01969       if (abs(plPrev%2)==0) plPrev=0;//even
01970       else if (abs(plPrev%2)==1) plPrev=1;//odd
01971     }
01972     if (plNext>59){
01973       if (plNext%2==0) plNext=58;//even
01974       else if (plNext%2==1) plNext=59;//odd
01975     }
01976     
01977     if (pl%2==0){//even planes, measures v and y
01978       //get position
01979       posPrev=plPosition[plPrev].X();
01980       posNext=plPosition[plNext].X();
01981     }
01982     else if (pl%2==1){//odd planes, measures u and x
01983       //get position
01984       posPrev=plPosition[plPrev].Y();
01985       posNext=plPosition[plNext].Y();
01986     }
01987     
01988     if (posPrev==initValue || posNext==initValue){
01989       MAXMSG("CDAnalysis",Msg::kDebug,500)
01990         <<"pl="<<pl<<", fLastPlane="<<fLastPlane
01991         <<", lastPl="<<lastPlane
01992         <<", not found position"
01993         <<", prev="<<posPrev<<", next="<<posNext
01994         <<endl;
01995     }
01996     else{
01997       //calc the new position
01998       pos=(posPrev+posNext)*0.5;
01999       MAXMSG("CDAnalysis",Msg::kDebug,1000)
02000         <<"pl="<<pl
02001         <<", found positions, prev="<<posPrev<<", next="<<posNext
02002         <<", pos="<<pos<<endl;
02003     }
02004     
02005     if (pl%2==0){//even planes, measures v and y
02006       //set position
02007       plPosition[pl].SetX(pos);
02008     }
02009     else if (pl%2==1){//odd planes, measures u and x
02010       //set position
02011       plPosition[pl].SetY(pos);
02012     }
02013   }
02014   
02015   //need to do a 3D vector type correction to work out the last plane
02016   //but hack for now - use same x/y as previous plane
02017   Int_t pl=lastPlane;
02018   if (pl%2==0){//even planes, measures v and y
02019     //set position
02020     Float_t lastPlX=plPosition[pl-1].X();
02021     plPosition[pl].SetX(lastPlX);
02022   }
02023   else if (pl%2==1){//odd planes, measures u and x
02024     //set position
02025     Float_t lastPlY=plPosition[pl-1].Y();
02026     plPosition[pl].SetY(lastPlY);
02027   }
02028   
02029   //MAXMSG("CDAnalysis",Msg::kInfo,200)
02030   //<<"fLastPlane="<<fLastPlane
02031   //<<", lastPl="<<lastPlane
02032   //<<endl;
02033   //loop and print positions
02034   //for (Int_t pl=0;pl<60;pl++){
02035   //MAXMSG("CDAnalysis",Msg::kInfo,5000)
02036   //  <<"pl="<<pl<<" (x,y,z)=("<<plPosition[pl].X()
02037   //  <<","<<plPosition[pl].Y()
02038   //  <<","<<plPosition[pl].Z()<<")"<<endl;
02039   //}
02040   
02041   //make map to return (not nice)
02042   for (Int_t pl=0;pl<60;pl++){
02043     mPlPos[pl]=plPosition[pl];
02044   }
02045   
02046   return true;
02047 }
02048 
02049 //......................................................................
02050 
02051 Float_t CDAnalysis::CalcDistToPlaneCentre(Int_t strip,
02052                                           Float_t transPos) const
02053 {
02054   Float_t stripSize=0.041*Munits::m;
02055   Float_t distToPlaneCentre=-1;
02056   //note that strips are numbered from 0  
02057 
02058   //cutting on transPos==0 is ugly since it's an allowed value
02059   //but this is what it is initialised to and it 
02060   //should only cut real values rarely
02061   if (strip<0 || strip>23 || transPos<0 || transPos==0 || 
02062       transPos>23) return distToPlaneCentre;
02063 
02064   Float_t dist1=-1;
02065   Float_t dist2=-1;
02066   Float_t stripsFromCentre1=-1;
02067   Float_t transPosFromCentre1=-1;
02068 
02069   //get distances measured from plane centre in each view
02070   if (strip<=11) stripsFromCentre1=11-strip;
02071   else if (strip>11) stripsFromCentre1=strip-12;
02072   if (transPos<=11) transPosFromCentre1=11-transPos;
02073   else if (transPos>11) transPosFromCentre1=transPos-11;
02074 
02075   //calc real distances
02076   dist1=stripsFromCentre1*stripSize;
02077   dist2=transPosFromCentre1*stripSize;
02078   
02079   //move it to the middle of a strip so 
02080   //you know which strip it's actually in
02081   dist1+=stripSize*0.5;
02082   //transPos is not quantised so don't worry about it here
02083 
02084   //simple bit of trig
02085   if (dist1>0 && dist2>0){
02086     distToPlaneCentre=sqrt(pow(dist1,2)+pow(dist2,2));
02087   }
02088   
02089   return distToPlaneCentre;
02090 }
02091 
02092 //......................................................................
02093 
02094 Float_t CDAnalysis::TrueDistToPlaneCentre(Int_t strip,
02095                                           Float_t x) const
02096 {
02097   Float_t stripSize=0.041*Munits::m;
02098   Float_t distToPlaneCentre=-1;
02099   //note that strips are numbered from 0  
02100 
02101   if (strip<0 || strip>23 || x>0.5 || x<-0.5) return distToPlaneCentre;
02102 
02103   Float_t dist1=-1;
02104   Float_t dist2=-1;
02105   Float_t stripsFromCentre1=-1;
02106 
02107   //get distances measured from plane centre in each view
02108   if (strip<=11) stripsFromCentre1=11-strip;
02109   else if (strip>11) stripsFromCentre1=strip-12;
02110   if (x<0) x=x-2*x;//convert to positive for later check
02111 
02112   //calc real distances
02113   dist1=stripsFromCentre1*stripSize;
02114   dist2=x;//don't need to do it for x  
02115 
02116   //move it to the middle of a strip so 
02117   //you know which strip it's actually in
02118   dist1+=stripSize*0.5;
02119 
02120   //simple bit of trig
02121   if (dist1>0 && dist2>0){
02122     distToPlaneCentre=sqrt(pow(dist1,2)+pow(dist2,2));
02123   }
02124   
02125   return distToPlaneCentre;
02126 }
02127 
02128 //......................................................................
02129 
02130 void CDAnalysis::StandardSanityChecks() const
02131 {
02132   //new check to not allow any capid errors
02133   if (fChargeAdc<1){
02134     MSG("CDAnalysis",Msg::kFatal)
02135       <<"Run has bad adcs!"<<endl
02136       <<"adc="<<fChargeAdc<<" ("<<fPlane<<":"<<fStrip<<":"<<fStripend
02137       <<")"<<endl;
02138     assert(false);
02139   }
02140 }
02141 
02142 //......................................................................
02143 
02144 void CDAnalysis::ScaleVector(std::vector<Double_t>& v,
02145                              Double_t scaleFactor) const
02146 {
02147   MSG("CDAnalysis",Msg::kDebug) 
02148     <<" ** Running ScaleVector method... **"<<endl;
02149 
02150   for (UInt_t i=0;i<v.size();i++) v[i]*=scaleFactor;
02151 
02152   MSG("CDAnalysis",Msg::kDebug) 
02153     <<" ** Finished ScaleVector method **"<<endl;
02154 }
02155 
02156 //......................................................................
02157 
02158 void CDAnalysis::FlipVector(std::vector<Double_t>& v) const
02159 {
02160   MSG("CDAnalysis",Msg::kDebug) 
02161     <<" ** Running FlipVector method... **"<<endl;
02162 
02163   vector<Double_t> tempV=v;
02164 
02165   for (UInt_t i=0;i<v.size();i++) v[i]=tempV[v.size()-1-i];
02166 
02167   MSG("CDAnalysis",Msg::kDebug) 
02168     <<" ** Finished FlipVector method **"<<endl;
02169 }
02170 
02171 //......................................................................
02172 
02173 Int_t CDAnalysis::Rnd(Double_t x) const
02174 {
02175   Double_t xi=0;
02176 
02177   Double_t floatPart=modf(x,&xi); 
02178 
02179   //round up if necessary
02180   if (floatPart>0.5) xi++;
02181 
02182   return static_cast<Int_t>(xi);
02183 }
02184 
02185 //......................................................................
02186 
02187 void CDAnalysis::ScaleMap(std::map<Int_t,Float_t>& m,
02188                           const std::map<Int_t,Float_t>& scaleFactor) const
02189 {
02190   MSG("CDAnalysis",Msg::kDebug) 
02191     <<" ** Running ScaleMap method... **"<<endl;
02192 
02193   if (m.size()==scaleFactor.size()){
02194     
02195     map<Int_t,Float_t>::iterator mIter=m.begin();
02196     map<Int_t,Float_t>::const_iterator scale=scaleFactor.begin();
02197 
02198     //loop over map and scale it
02199     while (mIter!=m.end()){
02200 
02201       //divide by the scale factor
02202       if (scale->second!=0){
02203         MSG("CDAnalysis",Msg::kVerbose)
02204           <<"mIter="<<mIter->second<<", scale="<<scale->second<<endl;
02205         mIter->second/=scale->second;
02206       }
02207       else MSG("CDAnalysis",Msg::kWarning)<<"Scale factor zero!"<<endl;
02208 
02209       mIter++;
02210       scale++;
02211     }
02212   }
02213   else{
02214     MSG("CDAnalysis",Msg::kWarning)
02215       <<"Not scaling map, vectors are different sizes!"<<endl;
02216   }
02217 
02218   MSG("CDAnalysis",Msg::kDebug) 
02219     <<" ** Finished ScaleMap method **"<<endl;
02220 }
02221 
02222 //......................................................................
02223 
02224 Bool_t CDAnalysis::CutOnFiducialVolume() const
02225 {
02226   Bool_t cutThisOne=false;
02227 
02228   Int_t stripsFromCentreCut=10;
02229 
02230   if (fStripsFromCentrePeCut>=stripsFromCentreCut) cutThisOne=true;
02231 
02232   if (cutThisOne){
02233     MAXMSG("CDAnalysis",Msg::kInfo,1)
02234       <<"Applying cut on fiducial volume:"<<endl
02235       <<" stripsFromCentre<"<<stripsFromCentreCut
02236       <<" (fStripsFromCentrePeCut="<<fStripsFromCentrePeCut<<")"
02237       <<endl;
02238   }
02239   
02240   return cutThisOne;
02241 }
02242 
02243 //......................................................................
02244 
02245 Bool_t CDAnalysis::CutOnNumHitsPerPlane() const
02246 {
02247   Bool_t cutThisOne=false;
02248 
02249   Float_t hitsPerPlLowCut=1.7;
02250   Float_t hitsPerPlCut=2.9;
02251 
02252   if (fNumHitsPerPlane<hitsPerPlLowCut ||
02253       fNumHitsPerPlane>hitsPerPlCut) cutThisOne=true;
02254 
02255   if (cutThisOne){
02256     MAXMSG("CDAnalysis",Msg::kInfo,1)
02257       <<"Applying cut on hits per plane:"
02258       <<" numHitsPerPlane<"<<hitsPerPlCut<<" and >"<<hitsPerPlLowCut
02259       <<" (fNumHitsPerPlane="<<fNumHitsPerPlane<<")"<<endl
02260       <<endl;
02261   }
02262   
02263   return cutThisOne;
02264 }
02265 
02266 //......................................................................
02267 
02268 Bool_t CDAnalysis::CutOnNumHitsPerPlane10() const
02269 {
02270   Bool_t cutThisOne=false;
02271 
02272   Float_t hitsPerPlPeCut10LowCut=1.1;
02273   Float_t hitsPerPlPeCut10Cut=2.7;
02274 
02275   if (fNumHitsPerPlanePeCut10<hitsPerPlPeCut10LowCut ||
02276       fNumHitsPerPlanePeCut10>hitsPerPlPeCut10Cut) cutThisOne=true;
02277 
02278   if (cutThisOne){
02279     MAXMSG("CDAnalysis",Msg::kInfo,1)
02280       <<"Applying cut on hits per plane:"
02281       <<" numHitsPerPlanePeCut10<"<<hitsPerPlPeCut10Cut
02282       <<" and >"<<hitsPerPlPeCut10LowCut
02283       <<" (fNumHitsPerPlanePeCut10="<<fNumHitsPerPlanePeCut10<<")"
02284       <<endl;
02285   }
02286   
02287   return cutThisOne;
02288 }
02289 
02290 //......................................................................
02291 
02292 Bool_t CDAnalysis::CutOnDeadChips() const
02293 {
02294   Bool_t cutThisOne=false;
02295 
02296   //check if dead chips
02297   if (fNumDeadChips>0) cutThisOne=true;
02298 
02299   if (cutThisOne){
02300     MAXMSG("CDAnalysis",Msg::kInfo,1)
02301       <<"Applying cut on dead chips:"
02302       <<" numDeadChips="<<fNumDeadChips<<endl;
02303   }
02304   
02305   return cutThisOne;
02306 }
02307 
02308 //......................................................................
02309 
02310 Bool_t CDAnalysis::CutOnBadPedestals(Int_t plane,Int_t strip,
02311                                      Int_t end) const
02312 {
02313   //only have bad channels in real data so return if not data
02314   if (fSimFlag!=SimFlag::kData) return false;
02315 
02316   Bool_t cutThisOne=false;
02317 
02318   //cut out the strips with bad pedestals
02319   //not sure exactly for which run number the problem was fixed
02320   //had gone away by 71266
02321   if (fRunNumber>=70000 && fRunNumber<=70888){
02322     if ((plane==21 || plane==41) && strip==19) cutThisOne=true;
02323   }
02324   else if (fRunNumber>40000 && fRunNumber<60000){
02325     //cut out the strips with bad pedestals
02326     if ((plane==21 || plane==41) && strip==19 && end==1){
02327       cutThisOne=true;
02328     }
02329     if ((plane==20 || plane==40) && strip==4 && end==2){
02330       cutThisOne=true;
02331     }
02332   }    
02333   
02334   //not sure about this, MK reported it bad
02335   //in the 30000s and 40000s (i.e. T11) 38,10,2 was bad
02336   
02337   if (cutThisOne){
02338     MAXMSG("CDAnalysis",Msg::kInfo,6)
02339       <<"Applying cut to bad pedestal channel:"
02340       <<" (pl="<<plane<<", str="<<strip<<", end="<<end<<")"<<endl;
02341   }
02342   
02343   return cutThisOne;
02344 }
02345 
02346 //......................................................................
02347 
02348 Bool_t CDAnalysis::CutOnBadCalorimetry(Int_t plane,Int_t strip,
02349                                        Int_t end) const
02350 {
02351   //only have bad channels in real data so return if not data
02352   if (fSimFlag!=SimFlag::kData) return false;
02353 
02354   Bool_t cutThisOne=false;
02355 
02356   //cut out the strips with bad calorimetry
02357   //do this for all run periods to be consistent
02358   if (fPlane==0 || fPlane==35) cutThisOne=true;
02359   
02360   if (cutThisOne){
02361     MAXMSG("CDAnalysis",Msg::kInfo,6)
02362       <<"Applying cut to bad calorimetry:"
02363       <<" (pl="<<plane<<", str="<<strip<<", end="<<end<<")"<<endl;
02364   }
02365   
02366   return cutThisOne;
02367 }
02368 
02369 //......................................................................
02370 
02371 Bool_t CDAnalysis::CutOnTrackQuality(Bool_t requireGoodTrack) const
02372 {
02373   //set default to not cut
02374   Bool_t cutThisOne=false;
02375 
02376   //look if a good first plane was found
02377   //this is a good indication of tracking success
02378   Bool_t goodFirstPlane=(fFirstPlane>=0 && fFirstPlane<59);
02379   if (requireGoodTrack){
02380     if (!goodFirstPlane) cutThisOne=true;
02381   }
02382 
02383   //don't do this as not necessary for MEU calibration
02384   //cut on the trackers opinion of what's a good track
02385   //Bool_t goodInBothViews=(fResultEven==1 && fResultOdd==1);
02386   //if (requireGoodTrack){
02387   //  if (!goodInBothViews) cutThisOne=true;
02388   //}
02389 
02390   if (cutThisOne){
02391     MAXMSG("CDAnalysis",Msg::kInfo,1)
02392       <<"Applying cut to track quality"<<endl;
02393   }
02394 
02395   return cutThisOne;
02396 }
02397 
02398 //......................................................................
02399 
02400 Bool_t CDAnalysis::CutOnOverlap() const
02401 {
02402   //set default to not cut
02403   Bool_t cutThisOne=false;
02404 
02405   //only have pid for real data so return if not data
02406   if (fSimFlag!=SimFlag::kData) return false;
02407 
02408   //if (!fNoOverlap){ //not no overlap=overlap
02409   //cutThisOne=true;
02410   //}
02411   Float_t olChi2Threshold=1.1;
02412   if (fOLChi2>olChi2Threshold) cutThisOne=true;
02413 
02414   if (cutThisOne){
02415     MAXMSG("CDAnalysis",Msg::kInfo,1)
02416       <<"Applying cut on overlap, OLChi2<"<<olChi2Threshold
02417       <<endl;
02418   }
02419 
02420   return cutThisOne;
02421 }
02422 
02423 //......................................................................
02424 
02425 Bool_t CDAnalysis::CutOnOverlapForElec() const
02426 {
02427   //set default to not cut
02428   Bool_t cutThisOne=false;
02429 
02430   //only have pid for real data so return if not data
02431   if (fSimFlag!=SimFlag::kData) return false;
02432 
02433   Float_t olChi2Threshold=1.1;
02434   if (fOLChi2>olChi2Threshold) cutThisOne=true;
02435 
02436   if (cutThisOne){
02437     MAXMSG("CDAnalysis",Msg::kInfo,1)
02438       <<"Applying cut on overlap for elec, OLChi2<"<<olChi2Threshold
02439       <<endl;
02440   }
02441 
02442   return cutThisOne;
02443 }
02444 
02445 //......................................................................
02446 
02447 Bool_t CDAnalysis::CutOnPidForElec() const
02448 {
02449   //set default to not cut
02450   Bool_t cutThisOne=false;
02451 
02452   //only have pid for real data so return if not data
02453   if (fSimFlag!=SimFlag::kData) return false;
02454 
02455   if (fPIDType!=CalDetParticleType::kElectron){ 
02456     cutThisOne=true;
02457   }
02458   if (!fInCERTime){ 
02459     cutThisOne=true;
02460   }
02461 
02462   if (cutThisOne){
02463     MAXMSG("CDAnalysis",Msg::kInfo,1)
02464       <<"Applying cut on pid to pass only electrons"<<endl;
02465   }
02466 
02467   return cutThisOne;
02468 }
02469 
02470 //......................................................................
02471 
02472 Bool_t CDAnalysis::CutByHandOnPidForElec() const
02473 {
02474   //set default to not cut
02475   Bool_t cutThisOne=false;
02476 
02477   //only have pid for real data so return if not data
02478   if (fSimFlag!=SimFlag::kData) return false;
02479 
02480   string particleSelection="for electrons";
02481   MAXMSG("CDAnalysis",Msg::kInfo,1)
02482     <<"Applying cut: "<<particleSelection<<endl;
02483 
02484   Bool_t elecKovADC1=false;
02485   Bool_t elecKovADC3=false;
02486   Bool_t goodTof=false;
02487   Bool_t elecInTime=false;
02488 
02489   if (fRunNumber==70579){//a 1 GeV run
02490 
02491     if (fTofTDC2-fTofTDC0>340 && fTofTDC2-fTofTDC0<500) goodTof=true;
02492 
02493     //don't analyse if not a elec
02494     if (!elecKovADC1) cutThisOne=true;
02495     if (!elecKovADC3) cutThisOne=true;
02496     
02497     //don't analyse if bad tof
02498     if (!goodTof) cutThisOne=true;
02499   }
02500   else if (fRunNumber==70709){
02501     MAXMSG("CDAnalysis",Msg::kInfo,1)
02502       <<"Applying cut: "<<particleSelection<<endl;
02503 
02504     if (fKovADC3>2000 && fKovADC3<3500) elecKovADC3=true;//elec ADC
02505     if (fKovADC1>1000 && fKovADC1<2500) elecKovADC1=true;
02506     if (fTofTDC2-fTofTDC0>385 && fTofTDC2-fTofTDC0<450) goodTof=true;
02507     //Tof in time with elec triggering kov
02508     if ((fTofADCTimeStamp1-fKovTimeStamp3)<-80 &&
02509         (fTofADCTimeStamp1-fKovTimeStamp3)>-85 &&
02510         (fTofADCTimeStamp1-fKovTimeStamp1)<-30 &&
02511         (fTofADCTimeStamp1-fKovTimeStamp1)>-40) elecInTime=true;
02512     
02513     //don't analyse if not a elec
02514     if (!elecKovADC1) cutThisOne=true;
02515     if (!elecKovADC3) cutThisOne=true;
02516     
02517     //don't analyse if bad tof
02518     if (!goodTof) cutThisOne=true;
02519     
02520     //don't analyse if tof not in time with kov set to elecs
02521     if (!elecInTime) cutThisOne=true;
02522 
02523   }
02524   else if (fRunNumber==71266){
02525 
02526   }
02527   else if (fRunNumber==100131){
02528 
02529   }
02530   else if (fRunNumber==100161){
02531 
02532     MAXMSG("CDAnalysis",Msg::kInfo,1)
02533       <<"Applying cut: "<<particleSelection<<endl;
02534 
02535     if (fKovADC3>1600 && fKovADC3<2100) elecKovADC3=true;//elec ADC
02536     if (fKovADC1>1100 && fKovADC1<3100) elecKovADC1=true;
02537     if (fTofTDC2-fTofTDC0>385 && fTofTDC2-fTofTDC0<470) goodTof=true;
02538     //Tof in time with elec triggering kov
02539     if ((fTofADCTimeStamp1-fKovTimeStamp3)<-20 &&
02540         (fTofADCTimeStamp1-fKovTimeStamp3)>-30 &&
02541         (fTofADCTimeStamp1-fKovTimeStamp1)<-50 &&
02542         (fTofADCTimeStamp1-fKovTimeStamp1)>-62) elecInTime=true;
02543     
02544     //don't analyse if not a elec
02545     if (!elecKovADC1) cutThisOne=true;
02546     if (!elecKovADC3) cutThisOne=true;
02547     
02548     //don't analyse if bad tof
02549     if (!goodTof) cutThisOne=true;
02550     
02551     //don't analyse if tof not in time with kov set to elecs
02552     if (!elecInTime) cutThisOne=true;
02553 
02554 
02555   }
02556   else if (fRunNumber==100243){
02557 
02558     
02559   }
02560   else if (fRunNumber==100270){
02561 
02562   }
02563   
02564   if (cutThisOne){
02565     MAXMSG("CDAnalysis",Msg::kInfo,1)
02566       <<"Applying 'by hand' cut on pid to pass only electrons"<<endl;
02567   }
02568 
02569   return cutThisOne;
02570 }
02571 
02572 //......................................................................
02573 
02574 Bool_t CDAnalysis::CutOnPid() const
02575 {
02576   //set default to not cut
02577   Bool_t cutThisOne=false;
02578 
02579   //only have pid for real data so return if not data
02580   if (fSimFlag!=SimFlag::kData) return false;
02581 
02582   Bool_t muonOrPion=fPIDType & (CalDetParticleType::kMuon |
02583                                 CalDetParticleType::kPion);
02584 
02585   if (!muonOrPion){ 
02586     cutThisOne=true;
02587   }
02588   if (!fInCERTime){ 
02589     cutThisOne=true;
02590   }
02591 
02592   if (cutThisOne){
02593     MAXMSG("CDAnalysis",Msg::kInfo,1)
02594       <<"Applying cut on pid to pass only pions and muons"<<endl;
02595   }
02596 
02597   return cutThisOne;
02598 }
02599 
02600 //......................................................................
02601 
02602 Bool_t CDAnalysis::CutByHandOnPid() const
02603 {
02604   //set default to not cut
02605   Bool_t cutThisOne=false;
02606 
02607   //only have pid for real data so return if not data
02608   if (fSimFlag!=SimFlag::kData) return false;
02609 
02610   Bool_t muonKovADC1=false;
02611   Bool_t muonKovADC3=false;
02612   Bool_t goodTof=false;
02613   Bool_t muonInTime=false;
02614 
02615   if (fRunNumber==70579){//a 1 GeV run
02616     if (fKovADC3<500) muonKovADC3=true;
02617     if (fKovADC1<300) muonKovADC1=true;//not an electron ADC
02618     if (fTofTDC2-fTofTDC0>340 && fTofTDC2-fTofTDC0<500) goodTof=true;
02619 
02620     //don't analyse if not a muon
02621     if (!muonKovADC1) cutThisOne=true;
02622     if (!muonKovADC3) cutThisOne=true;
02623     
02624     //don't analyse if bad tof
02625     if (!goodTof) cutThisOne=true;
02626   }
02627   else if (fRunNumber==70709){
02628     //string particleSelection="muons";
02629     string particleSelection="notElectrons";
02630     //string particleSelection="notElectronsNoCkv";
02631 
02632     if (particleSelection=="muons"){
02633       MAXMSG("CDAnalysis",Msg::kWarning,1)
02634         <<"Applying cut: "<<particleSelection<<endl;
02635       
02636       if (fKovADC3<1400 && fKovADC3>0) muonKovADC3=true;//muon ADC
02637       if (fKovADC1<500) muonKovADC1=true;//not an electron ADC
02638       if (fTofTDC2-fTofTDC0>385 && fTofTDC2-fTofTDC0<450) goodTof=true;
02639       //Tof in time with muon triggering kov
02640       if ((fTofADCTimeStamp1-fKovTimeStamp3)<-78 &&
02641           (fTofADCTimeStamp1-fKovTimeStamp3)>-96) muonInTime=true;
02642       
02643       //don't analyse if not a muon
02644       if (!muonKovADC1) cutThisOne=true;
02645       if (!muonKovADC3) cutThisOne=true;
02646       
02647       //don't analyse if bad tof
02648       if (!goodTof) cutThisOne=true;
02649       
02650       //don't analyse if tof not in time with kov set to muons
02651       if (!muonInTime) cutThisOne=true;
02652     }
02653     else if (particleSelection=="notElectrons"){
02654       MAXMSG("CDAnalysis",Msg::kWarning,1)
02655         <<"Applying cut: "<<particleSelection<<endl;
02656       
02657       if (fKovADC3<1400) muonKovADC3=true;//not an electron ADC
02658       if (fKovADC1<500) muonKovADC1=true;//not an electron ADC
02659       if (fTofTDC2-fTofTDC0>385 && fTofTDC2-fTofTDC0<450) goodTof=true;
02660       
02661       //don't analyse if not a muon
02662       if (!muonKovADC1) cutThisOne=true;
02663       if (!muonKovADC3) cutThisOne=true;
02664       
02665       //don't analyse if bad tof
02666       if (!goodTof) cutThisOne=true;
02667 
02668       //don't want the muon in time cut
02669     }
02670   }
02671   else if (fRunNumber==71266){
02672     if (fKovADC3<1400) muonKovADC3=true;//not an electron ADC
02673     if (fKovADC1<1000) muonKovADC1=true;//not an electron ADC
02674     if (fTofTDC2-fTofTDC0>385 && fTofTDC2-fTofTDC0<450) goodTof=true;
02675 
02676     //don't analyse if not a muon
02677     if (!muonKovADC1) cutThisOne=true;
02678     if (!muonKovADC3) cutThisOne=true;
02679     
02680     //don't analyse if bad tof
02681     if (!goodTof) cutThisOne=true;
02682   }
02683   else if (fRunNumber==100131){
02684     if (fKovADC3<1000) muonKovADC3=true;
02685     if (fKovADC1<500) muonKovADC1=true;//not an electron ADC
02686     if (fTofTDC2-fTofTDC0>370 && fTofTDC2-fTofTDC0<525) goodTof=true;
02687 
02688     //don't analyse if not a muon
02689     if (!muonKovADC1) cutThisOne=true;
02690     if (!muonKovADC3) cutThisOne=true;
02691     
02692     //don't analyse if bad tof
02693     if (!goodTof) cutThisOne=true;
02694   }
02695   else if (fRunNumber==100161){
02696 
02697     //string particleSelection="muons";
02698     string particleSelection="notElectrons";
02699     //string particleSelection="notElectronsNoCkv";
02700 
02701     if (particleSelection=="muons"){
02702       MAXMSG("CDAnalysis",Msg::kWarning,1)
02703         <<"Applying cut: "<<particleSelection<<endl;
02704 
02705       if (fKovADC3<850 && fKovADC3>0) muonKovADC3=true;
02706       if (fKovADC1<400) muonKovADC1=true;//not an electron ADC
02707       if (fTofTDC2-fTofTDC0>385 && fTofTDC2-fTofTDC0<490) goodTof=true;
02708       //Tof in time with muon triggering kov
02709       if ((fTofADCTimeStamp1-fKovTimeStamp3)<-24 &&
02710           (fTofADCTimeStamp1-fKovTimeStamp3)>-45) muonInTime=true;
02711       
02712       //don't analyse if not a muon
02713       if (!muonKovADC1) cutThisOne=true;
02714       if (!muonKovADC3) cutThisOne=true;
02715       
02716       //don't analyse if bad tof
02717       if (!goodTof) cutThisOne=true;
02718       
02719       //don't analyse if tof not in time with kov set to muons
02720       if (!muonInTime) cutThisOne=true;
02721     }
02722     else if (particleSelection=="notElectrons"){
02723       MAXMSG("CDAnalysis",Msg::kWarning,1)
02724         <<"Applying cut: "<<particleSelection<<endl;
02725 
02726       if (fKovADC3<850) muonKovADC3=true;
02727       if (fKovADC1<400) muonKovADC1=true;//not an electron ADC
02728       if (fTofTDC2-fTofTDC0>385 && fTofTDC2-fTofTDC0<490) goodTof=true;
02729 
02730       //don't analyse if not a muon
02731       if (!muonKovADC1) cutThisOne=true;
02732       if (!muonKovADC3) cutThisOne=true;
02733       
02734       //don't analyse if bad tof
02735       if (!goodTof) cutThisOne=true;
02736 
02737       //don't want the muon in time cut
02738     }
02739     else if (particleSelection=="notElectronsNoCkv"){
02740       MAXMSG("CDAnalysis",Msg::kWarning,1)
02741         <<"Applying cut: "<<particleSelection<<endl;
02742 
02743       if (fKovADC3<100) muonKovADC3=true;
02744       if (fKovADC1<100) muonKovADC1=true;//not an electron ADC
02745       if (fTofTDC2-fTofTDC0>385 && fTofTDC2-fTofTDC0<490) goodTof=true;
02746 
02747       //don't analyse if not a muon
02748       if (!muonKovADC1) cutThisOne=true;
02749       if (!muonKovADC3) cutThisOne=true;
02750       
02751       //don't analyse if bad tof
02752       if (!goodTof) cutThisOne=true;
02753 
02754       //don't want the muon in time cut
02755     }
02756   }
02757   else if (fRunNumber==100243){
02758     if (fKovADC3<900) muonKovADC3=true;
02759     if (fKovADC1<1000) muonKovADC1=true;//not an electron ADC
02760     if (fTofTDC2-fTofTDC0>350 && fTofTDC2-fTofTDC0<490) goodTof=true;
02761 
02762     //don't analyse if not a muon
02763     if (!muonKovADC1) cutThisOne=true;
02764     if (!muonKovADC3) cutThisOne=true;
02765     
02766     //don't analyse if bad tof
02767     if (!goodTof) cutThisOne=true;
02768     
02769   }
02770   else if (fRunNumber==100270){
02771     if (fKovADC3<1100) muonKovADC3=true;
02772     if (fKovADC1<500) muonKovADC1=true;//not an electron ADC
02773     if (fTofTDC2-fTofTDC0>360 && fTofTDC2-fTofTDC0<525) goodTof=true;
02774 
02775     //don't analyse if not a muon
02776     if (!muonKovADC1) cutThisOne=true;
02777     if (!muonKovADC3) cutThisOne=true;
02778     
02779     //don't analyse if bad tof
02780     if (!goodTof) cutThisOne=true;    
02781   }
02782 
02783   if (cutThisOne){
02784     MAXMSG("CDAnalysis",Msg::kInfo,1)
02785       <<"Applying 'by hand' cut on pid"<<endl;
02786   }
02787 
02788   return cutThisOne;
02789 }
02790 
02791 //......................................................................
02792 
02793 Bool_t CDAnalysis::CutOnScint_TofDiff() const
02794 {
02795   //set default to not cut
02796   Bool_t cutThisOne=false;
02797 
02798   Float_t lowTime=-1000000;
02799   Float_t upTime=1000000;
02800   
02801   this->GetLowUpTimeCuts(lowTime,upTime);
02802   
02803   if (fLowScint_Tof<lowTime || fUpScint_Tof>upTime) cutThisOne=true;
02804 
02805   if (cutThisOne){
02806     MAXMSG("CDAnalysis",Msg::kInfo,10)
02807       <<"Using TOF-scint diff. cut: "
02808       <<lowTime<<" -> "<<upTime<<" ns"
02809       <<" (t="<<fLowScint_Tof<<" -> "<<fUpScint_Tof<<" ns)"
02810       <<endl;
02811   }
02812 
02813   return cutThisOne;
02814 }
02815 
02816 //......................................................................
02817 
02818 void CDAnalysis::GetLowUpTimeCuts(Float_t& lowTime,
02819                                   Float_t& upTime) const
02820 {
02821   //this works in ns rather naughtily!
02822   lowTime=-1000000;
02823   upTime=1000000;
02824 
02825   Int_t run=fRunNumber;
02826 
02827   //set the time gate here so that you get the same for each run 
02828   //period
02829   Int_t lowTimeLimit=35;
02830   Int_t upTimeLimit=295;
02831   Int_t peak=-1;
02832   
02833   //only have timing issues for real data
02834   if (fSimFlag==SimFlag::kData) {
02835     if (run>=40000 && run<50000){
02836       //just for interest: the peak is 180 ns into the 600 ns varc gate
02837       peak=-125;//ns
02838       lowTime=peak-lowTimeLimit;//was -175;
02839       upTime=peak+upTimeLimit;//was 135;
02840     }
02841     else if (run>=50000 && run<60000){
02842       //just for interest: the peak is 280 ns into the 600 ns varc gate
02843       peak=30;//ns
02844       lowTime=peak-lowTimeLimit;
02845       upTime=peak+upTimeLimit;
02846     }
02847     else if (run>=70000 && run<80000){
02848       //just for interest: the peak is 220 ns into the 600 ns varc gate
02849       peak=5;//ns
02850       lowTime=peak-lowTimeLimit;//-30;//-50;
02851       upTime=peak+upTimeLimit;//300;//260;
02852     }
02853     else{
02854       MAXMSG("CDAnalysis",Msg::kInfo,10)
02855         <<"No time cuts cut for this run="<<fRunNumber<<endl;
02856     }
02857   }
02858   else{
02859     MAXMSG("CDAnalysis",Msg::kInfo,1)
02860       <<"MC data so no sensible timing cuts to set"<<endl;
02861   }
02862 
02863   MAXMSG("CDAnalysis",Msg::kInfo,1)
02864     <<"Set time cuts:  low="<<lowTime<<" ns, upper="<<upTime<<" ns"
02865     <<endl;
02866 }
02867 
02868 //......................................................................
02869 
02870 Bool_t CDAnalysis::CutOnEventLengthForElec() const
02871 {
02872   //set default to not cut
02873   Bool_t cutThisOne=false;
02874 
02875   //Int_t minPlane=0;
02876   Int_t maxPlane=20;
02877 
02878   //old cut
02879   //if (fLastPlane<minPlane || fLastPlane>maxPlane) cutThisOne=true;
02880 
02881   //new cut - number of planes hit allows for a noise hit in the
02882   //back of the detector but will cut out muons sucessfully
02883   Int_t numPlanes=fNumPlanesHitAll.size();
02884   if (numPlanes>maxPlane) cutThisOne=true;
02885 
02886   if (cutThisOne){
02887     MAXMSG("CDAnalysis",Msg::kInfo,1)
02888       <<"Using event length cuts for electrons: "
02889       <<"Num hit planes<="<<maxPlane<<endl;
02890   }
02891 
02892   return cutThisOne;
02893 }
02894 
02895 //......................................................................
02896 
02897 void CDAnalysis::GetEvLenMinMax(Int_t& minPlane,Int_t& maxPlane) const
02898 {
02899   //I don't understand abs. Sometimes it just returns an int!!
02900   //e.g. in a root macro
02901   Float_t aBeamP=fabs(fBeamMomentum);
02902   
02903   //new cuts are now inclusive so it's 31<=Pl<=45
02904 
02905   if (fabs(fBeamMomentum)>1.3 && fabs(fBeamMomentum)<1.5){
02906     minPlane=31;//minPlane=35;
02907     maxPlane=45;//maxPlane=44;
02908   }
02909   else if (fabs(fBeamMomentum)>1.5 && fabs(fBeamMomentum)<1.7){
02910     minPlane=35;//minPlane=40;
02911     maxPlane=51;//maxPlane=49;
02912   }
02913   else if (fabs(fBeamMomentum)>1.7 && fabs(fBeamMomentum)<1.9){
02914     minPlane=39;//minPlane=42;
02915     maxPlane=56;//maxPlane=57;
02916   }
02917   else if (fabs(fBeamMomentum)>1.9){
02918     minPlane=44;//minPlane=44;
02919     maxPlane=57;//maxPlane=58;
02920   }
02921   else{
02922     MAXMSG("CDAnalysis",Msg::kInfo,10)
02923       <<"No event length cut for this particle energy="
02924       <<fBeamMomentum<<endl;
02925     assert(false);
02926   }
02927   MAXMSG("CDAnalysis",Msg::kInfo,1)
02928     <<"Set Ev. Len min="<<minPlane<<", max="<<maxPlane
02929     <<", aBeamP="<<aBeamP<<endl;
02930 }
02931 
02932 //......................................................................
02933 
02934 Bool_t CDAnalysis::CutOnNumPlanesHit(Int_t planesHit) const
02935 {
02936   //set default to not cut
02937   Bool_t cutThisOne=false;
02938 
02939   Int_t minPlane=0;
02940   Int_t maxPlane=60;
02941 
02942   this->GetEvLenMinMax(minPlane,maxPlane);
02943 
02944   //new cuts are now inclusive so it's 31<=Pl<=45
02945   if (planesHit<minPlane || planesHit>maxPlane) cutThisOne=true;
02946 
02947   if (cutThisOne){
02948     MAXMSG("CDAnalysis",Msg::kInfo,1)
02949       <<"Using num planes hit cut to pass muons: "
02950       <<minPlane<<"<=Plane<="<<maxPlane
02951       <<", fBeamMomentum="<<fBeamMomentum<<endl;
02952   }
02953 
02954   MSG("CDAnalysis",Msg::kDebug)
02955     <<"fLastPlane="<<fLastPlane<<", cut this one="<<cutThisOne<<endl;
02956 
02957   return cutThisOne;
02958 }
02959 
02960 //......................................................................
02961 
02962 Bool_t CDAnalysis::CutOnPSMuons() const
02963 {
02964   //set default to not cut
02965   Bool_t cutThisOne=false;
02966 
02967   if (fAvStrip<9|| fAvStrip>13){
02968     cutThisOne=true;
02969   }
02970 
02971   return cutThisOne;
02972 }
02973 
02974 //......................................................................
02975 
02976 Int_t CDAnalysis::GetEventLength() const
02977 {
02978   Int_t lastPlane=fLastPlane;
02979   
02980   //if there was no track then a last plane is not found
02981   //in this case use the number of planes hit
02982   //this will be fairly rare for muons
02983   if (lastPlane==-1) {
02984     MAXMSG("CDAnalysis",Msg::kInfo,1)
02985       <<"GetEventLength::Using num planes hit in event length:"
02986       <<" fLastPlane="<<fLastPlane
02987       <<", numPlanesHit="<<fNumPlanesHitAll.size()<<endl;
02988     lastPlane=fNumPlanesHitAll.size();
02989   }
02990   
02991   return lastPlane;
02992 }
02993 
02994 //......................................................................
02995 
02996 Bool_t CDAnalysis::CutOnEventLength() const
02997 {
02998   //set default to not cut
02999   Bool_t cutThisOne=false;
03000 
03001   Int_t lastPlane=this->GetEventLength();
03002   
03003   Int_t minPlane=0;
03004   Int_t maxPlane=60;
03005   this->GetEvLenMinMax(minPlane,maxPlane);
03006 
03007   //new cuts are now inclusive so it's 31<=Pl<=45
03008   if (lastPlane<minPlane || lastPlane>maxPlane) cutThisOne=true;
03009 
03010   if (cutThisOne){
03011     MAXMSG("CDAnalysis",Msg::kInfo,1)
03012       <<"Using event length cuts to pass muons: "
03013       <<minPlane<<"<=Plane<="<<maxPlane
03014       <<" (lastPlane="<<lastPlane<<")"
03015       <<", fBeamMomentum="<<fBeamMomentum<<endl;
03016   }
03017 
03018   MSG("CDAnalysis",Msg::kDebug)
03019     <<"fLastPlane="<<fLastPlane<<", cut this one="<<cutThisOne<<endl;
03020 
03021   return cutThisOne;
03022 }
03023 
03024 //......................................................................
03025 
03026 Bool_t CDAnalysis::CutByHandOnEventLength() const
03027 {
03028   //set default to not cut
03029   Bool_t cutThisOne=false;
03030 
03031   Int_t minPlane=0;
03032   Int_t maxPlane=60;
03033 
03034   if (fSimFlag==SimFlag::kData){
03035     
03036     //might want to tighten these up to boost the signal to noise ratio
03037     
03038     if (fRunNumber==70709 ||
03039         fRunNumber==71266 ||
03040         fRunNumber==100161 ||
03041         fRunNumber==100270){//1.8
03042       //cut out through going muons, no 58,59
03043       minPlane=42;
03044       maxPlane=57;
03045       if (fLastPlane<minPlane || fLastPlane>maxPlane) cutThisOne=true;
03046     }
03047     else if (fRunNumber==100243){//1.6
03048       minPlane=40;
03049       maxPlane=49;
03050       if (fLastPlane<minPlane || fLastPlane>maxPlane) cutThisOne=true;
03051     }
03052     else if (fRunNumber==100131){//1.4
03053       minPlane=35;
03054       maxPlane=44;
03055       if (fLastPlane<minPlane || fLastPlane>maxPlane) cutThisOne=true;
03056     }
03057     else if (fRunNumber==70579){//1.0 GeV run
03058       //hack - these are 1.8 cuts
03059       if (fLastPlane<42 || fLastPlane>57) cutThisOne=true;
03060     }
03061   }
03062   else if (fSimFlag==SimFlag::kMC){
03063     
03064     if (fMainParticleEnergy>1.3 && fMainParticleEnergy<1.5){
03065       minPlane=35;
03066       maxPlane=44;
03067       if (fLastPlane<minPlane || fLastPlane>maxPlane) cutThisOne=true;
03068     }
03069     else if (fMainParticleEnergy>1.5 && fMainParticleEnergy<1.7){
03070       minPlane=40;
03071       maxPlane=49;
03072       if (fLastPlane<minPlane || fLastPlane>maxPlane) cutThisOne=true;
03073     }
03074     else if (fMainParticleEnergy>1.7 && fMainParticleEnergy<1.9){
03075       minPlane=42;
03076       maxPlane=57;
03077       if (fLastPlane<minPlane || fLastPlane>maxPlane) cutThisOne=true;
03078     }
03079     else if (fMainParticleEnergy>1.9){
03080       minPlane=44;
03081       maxPlane=58;//last but one, so didn't exit
03082       if (fLastPlane<minPlane || fLastPlane>maxPlane) cutThisOne=true;
03083     }
03084     else{
03085       MAXMSG("CDAnalysis",Msg::kInfo,10)
03086         <<"No event length cut for this particle energy="
03087         <<fMainParticleEnergy<<endl;
03088     }
03089   }
03090 
03091   if (cutThisOne){
03092     MAXMSG("CDAnalysis",Msg::kInfo,1)
03093       <<"Using 'by hand' event length cuts to pass muons: "
03094       <<minPlane<<"<Plane<"<<maxPlane
03095       <<", fBeamMomentum="<<fBeamMomentum<<endl;
03096   }
03097 
03098   MSG("CDAnalysis",Msg::kDebug)
03099     <<"fLastPlane="<<fLastPlane<<", cut this one="<<cutThisOne<<endl;
03100 
03101   return cutThisOne;
03102 }
03103 
03104 //......................................................................
03105 
03106 void CDAnalysis::FillProfHisto(TProfile* prof,
03107                                std::map<Int_t,Float_t>& counter,
03108                                const std::map<Int_t,Float_t>& addMe,
03109                                Int_t offset) const
03110 {
03111   if (prof){
03112     for (map<Int_t,Float_t>::const_iterator it=addMe.begin();
03113          it!=addMe.end();++it){
03114       Int_t key=it->first;
03115       if (offset!=0) key=offset-(it->first);
03116 
03117       prof->Fill(key,it->second);
03118       counter[key]++;
03119     }
03120   }
03121   else{
03122     MSG("CDAnalysis",Msg::kWarning)
03123       <<"TProfile not initialised"<<endl;
03124   }
03125 }
03126 
03127 //......................................................................
03128 
03129 Bool_t CDAnalysis::IsPlaneXTalkOnly(Int_t inplane) const
03130 {
03131   if (!fTruthHitInfo) return false;
03132 
03133   TClonesArray &cTruth = *fTruthHitInfo;
03134   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03135   
03136   Int_t sumTruth=DigiSignal::kUnknown;
03137 
03138   //loop over the truth hits
03139   for (Int_t hit=0;hit<numTruthHits;hit++){
03140     //cast the tclonesarray up to a truthhitinfo object
03141     CDTruthHitInfo *hitInfo=
03142       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03143     
03144     Int_t plane=hitInfo->GetPlane();
03145 
03146     if (plane!=inplane) continue;
03147 
03148     Int_t pmtTruth1=hitInfo->GetPmtTruth1();
03149     Int_t pmtTruth2=hitInfo->GetPmtTruth2();
03150 
03151     //add up the bits
03152     sumTruth|=pmtTruth1;
03153     sumTruth|=pmtTruth2;
03154 
03155     MSG("CDAnalysis",Msg::kVerbose)
03156       <<"sumTruth="<<sumTruth<<endl;
03157   }
03158 
03159   //check if genuine or not
03160   Bool_t genuineBit=((sumTruth & DigiSignal::kGenuine)==
03161                      DigiSignal::kGenuine);
03162   Bool_t optXTalkBit=((sumTruth & DigiSignal::kCrosstalkOptical)==
03163                       DigiSignal::kCrosstalkOptical);
03164   Bool_t xTalkBit=((sumTruth & DigiSignal::kCrosstalk)==
03165                    DigiSignal::kCrosstalk);
03166   
03167   if (genuineBit || sumTruth==0) return false;
03168   else if (optXTalkBit) return true;
03169   else if (xTalkBit) return true;
03170   else return false;
03171 }
03172 
03173 //......................................................................
03174 
03175 Bool_t CDAnalysis::IsPlaneGenuine(Int_t inplane) const
03176 {
03177   if (!fTruthHitInfo) return true;
03178 
03179   MAXMSG("CDAnalysis",Msg::kInfo,1)
03180     <<"Running IsPlaneGenuine(), fTruthHitInfo="<<fTruthHitInfo<<endl;
03181 
03182   TClonesArray &cTruth = *fTruthHitInfo;
03183   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03184   
03185   Int_t sumTruth=DigiSignal::kUnknown;
03186 
03187   //loop over the truth hits
03188   for (Int_t hit=0;hit<numTruthHits;hit++){
03189     //cast the tclonesarray up to a truthhitinfo object
03190     CDTruthHitInfo *hitInfo=
03191       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03192     
03193     Int_t plane=hitInfo->GetPlane();
03194 
03195     if (plane!=inplane) continue;
03196 
03197     Int_t pmtTruth1=hitInfo->GetPmtTruth1();
03198     Int_t pmtTruth2=hitInfo->GetPmtTruth2();
03199 
03200     //add up the bits
03201     sumTruth|=pmtTruth1;
03202     sumTruth|=pmtTruth2;
03203 
03204     MSG("CDAnalysis",Msg::kVerbose)
03205       <<"sumTruth="<<sumTruth<<endl;
03206   }
03207 
03208   //check if genuine or not
03209   Bool_t genuineBit=((sumTruth & DigiSignal::kGenuine)==
03210                      DigiSignal::kGenuine);
03211   
03212   if (genuineBit) return true;
03213   else return false;
03214 }
03215 
03216 //......................................................................
03217 
03218 Bool_t CDAnalysis::IsSharedPmtHit(Int_t inplane) const
03219 {
03220   if (!fTruthHitInfo) return true;
03221 
03222   TClonesArray &cTruth = *fTruthHitInfo;
03223   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03224   
03225   Bool_t sharedPmtHit=false;
03226 
03227   //loop over the truth hits
03228   for (Int_t hit=0;hit<numTruthHits;hit++){
03229     //cast the tclonesarray up to a truthhitinfo object
03230     CDTruthHitInfo *hitInfo=
03231       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03232     
03233     Int_t plane=hitInfo->GetPlane();
03234     
03235     if (plane!=inplane) continue;
03236     
03237     Int_t vaChip1=hitInfo->GetVaChip1();
03238     Int_t vaChip2=hitInfo->GetVaChip2();
03239 
03240     if (vaChip1==1 || vaChip2==1) sharedPmtHit=true;
03241 
03242     MSG("CDAnalysis",Msg::kVerbose)
03243       <<"sharedPmtHit="<<sharedPmtHit<<endl;
03244   }
03245 
03246   return sharedPmtHit;
03247 }
03248 
03249 //......................................................................
03250 
03251 Bool_t CDAnalysis::IsPlaneSideHit(Int_t inplane,Int_t stripEnd) const
03252 {
03253   if (!fTruthHitInfo) return true;
03254 
03255   TClonesArray &cTruth = *fTruthHitInfo;
03256   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03257   
03258   Bool_t planeSideHit=false;
03259 
03260   //loop over the truth hits
03261   for (Int_t hit=0;hit<numTruthHits;hit++){
03262     //cast the tclonesarray up to a truthhitinfo object
03263     CDTruthHitInfo *hitInfo=
03264       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03265     
03266     Int_t plane=hitInfo->GetPlane();
03267     
03268     if (plane!=inplane) continue;
03269 
03270     Int_t pmtTruth1=hitInfo->GetPmtTruth1();
03271     Int_t pmtTruth2=hitInfo->GetPmtTruth2();
03272     
03273 
03274     if (pmtTruth1 && stripEnd==StripEnd::kEast){
03275       planeSideHit=true;
03276       break;//only need the one hit
03277     }
03278     if (pmtTruth2 && stripEnd==StripEnd::kWest){
03279       planeSideHit=true;
03280       break;//only need the one hit
03281     }
03282   }
03283 
03284   MSG("CDAnalysis",Msg::kVerbose)
03285     <<"planeSideHit="<<planeSideHit<<endl;
03286 
03287   return planeSideHit;
03288 }
03289 
03290 //......................................................................
03291 
03292 Bool_t CDAnalysis::IsDoubleEnded(Int_t inplane) const
03293 {
03294   if (!fTruthHitInfo) return true;
03295 
03296   TClonesArray &cTruth = *fTruthHitInfo;
03297   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03298   
03299   Bool_t doubleEnded=false;
03300 
03301   //loop over the truth hits
03302   for (Int_t hit=0;hit<numTruthHits;hit++){
03303     //cast the tclonesarray up to a truthhitinfo object
03304     CDTruthHitInfo *hitInfo=
03305       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03306     
03307     Int_t plane=hitInfo->GetPlane();
03308     
03309     if (plane!=inplane) continue;
03310     
03311     Int_t pmtTruth1=hitInfo->GetPmtTruth1();
03312     Int_t pmtTruth2=hitInfo->GetPmtTruth2();
03313 
03314     if (pmtTruth1 && pmtTruth2) doubleEnded=true;
03315 
03316     MSG("CDAnalysis",Msg::kVerbose)
03317       <<"doubleEnded="<<doubleEnded<<endl;
03318   }
03319 
03320   return doubleEnded;
03321 }
03322 
03323 //......................................................................
03324 
03325 Bool_t CDAnalysis::IsGenuineOrXTalk(Int_t inplane) const
03326 {
03327   if (!fTruthHitInfo) return true;
03328 
03329   TClonesArray &cTruth = *fTruthHitInfo;
03330   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03331   
03332   Int_t sumTruth=DigiSignal::kUnknown;
03333 
03334   //loop over the truth hits
03335   for (Int_t hit=0;hit<numTruthHits;hit++){
03336     //cast the tclonesarray up to a truthhitinfo object
03337     CDTruthHitInfo *hitInfo=
03338       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03339     
03340     Int_t plane=hitInfo->GetPlane();
03341     
03342     if (plane!=inplane) continue;
03343     
03344     Int_t pmtTruth1=hitInfo->GetPmtTruth1();
03345     Int_t pmtTruth2=hitInfo->GetPmtTruth2();
03346 
03347     //add up the bits
03348     sumTruth|=pmtTruth1;
03349     sumTruth|=pmtTruth2;
03350   }
03351   
03352   MSG("CDAnalysis",Msg::kVerbose)
03353     <<"sumTruth(GenOrXTalk)="<<sumTruth<<endl;
03354 
03355   Bool_t genuineBit=((sumTruth & DigiSignal::kGenuine)==
03356                      DigiSignal::kGenuine);
03357   Bool_t optXTalkBit=((sumTruth & DigiSignal::kCrosstalkOptical)==
03358                       DigiSignal::kCrosstalkOptical);
03359   Bool_t xTalkBit=((sumTruth & DigiSignal::kCrosstalk)==
03360                    DigiSignal::kCrosstalk);
03361 
03362   if (genuineBit || optXTalkBit) return true;
03363   else if (xTalkBit){
03364     MSG("CDAnalysis",Msg::kDebug)
03365       <<" **** Only non-optXTalk, sumTruth="<<sumTruth<<endl;
03366     return false;
03367   }
03368   else{
03369     MSG("CDAnalysis",Msg::kDebug)
03370       <<"Not genuine or xtalk, sumTruth="<<sumTruth<<endl;
03371     return false;
03372   }
03373 }
03374 
03375 //......................................................................
03376 
03377 Bool_t CDAnalysis::StraightTrack_Radius(Double_t radiusCut) const
03378 {
03379   //check if positive
03380   if (radiusCut<0) radiusCut=radiusCut-2*radiusCut;
03381   
03382   //set default return value to true
03383   Bool_t straight=true;
03384 
03385   //get tclones arrays for this snarl
03386   TClonesArray &cTrk=*fTrkHitInfo;
03387   Int_t numTrkHits=fTrkHitInfo->GetEntries();
03388   
03389   for (Int_t hit=0;hit<numTrkHits;hit++){
03390     CDTrackedHitInfo *trackedHitInfo=
03391       dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
03392     
03393     Int_t strip=trackedHitInfo->GetStrip();
03394     Double_t transPos=trackedHitInfo->GetTransPos();
03395 
03396     //calc dist to plane centre
03397     Float_t radius=this->CalcDistToPlaneCentre(strip,transPos);
03398 
03399     //test for straight tracks
03400     if (radius>radiusCut){
03401       straight=false;
03402       break;
03403     } 
03404   }
03405 
03406   //return result
03407   return straight;
03408 }
03409 
03410 //......................................................................
03411 
03412 Bool_t CDAnalysis::IsStraightTrack_Radius(Double_t radiusCut) const
03413 {
03414   if (!fTruthHitInfo) return true;
03415 
03416   //this method will get called once per event so use event to satisfy
03417   //the TrueXInStripFrame method used below
03418   //bit of a hack but it should work fine
03419   static Int_t event=0;
03420   event++;
03421 
03422   //check if positive
03423   if (radiusCut<0) radiusCut=radiusCut-2*radiusCut;
03424 
03425   TClonesArray &cTruth = *fTruthHitInfo;
03426   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03427   
03428   //set default return value to true
03429   Bool_t straight=true;
03430 
03431   //loop over the truth hits
03432   for (Int_t hit=0;hit<numTruthHits;hit++){
03433     //cast the tclonesarray up to a truthhitinfo object
03434     CDTruthHitInfo *hitInfo=
03435       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03436     
03437     Int_t mainParticle=hitInfo->GetMainParticle();
03438     Int_t plane=hitInfo->GetPlane();
03439     Int_t strip=hitInfo->GetStrip();
03440     Int_t muon=13;
03441 
03442     if (abs(mainParticle)!=muon) continue;
03443 
03444     Float_t trueX=this->TrueXInStripFrame(plane,strip,event);   
03445     Float_t radiusTrue=this->TrueDistToPlaneCentre(strip,trueX);
03446     MAXMSG("CDAnalysis",Msg::kVerbose,300)
03447       <<"trueX="<<trueX<<", trueRadius="<<radiusTrue
03448       <<", striaght="<<straight<<", radiusCut="<<radiusCut<<endl;
03449 
03450     //test for straight tracks
03451     if (radiusTrue>radiusCut){
03452       straight=false;
03453       break;
03454     }
03455   }
03456 
03457   MAXMSG("CDAnalysis",Msg::kVerbose,100)
03458     <<"Returning straight="<<straight<<endl;
03459 
03460   //return result
03461   return straight;
03462 }
03463 
03464 //......................................................................
03465 
03466 Bool_t CDAnalysis::IsStraightTrack(Double_t mainX1Cut) const
03467 {
03468   if (!fTruthHitInfo) return true;
03469 
03470   TClonesArray &cTruth = *fTruthHitInfo;
03471   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03472   
03473   //set default return value to true
03474   Bool_t straight=true;
03475 
03476   //loop over the truth hits
03477   for (Int_t hit=0;hit<numTruthHits;hit++){
03478     //cast the tclonesarray up to a truthhitinfo object
03479     CDTruthHitInfo *hitInfo=
03480       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03481     
03482     Int_t mainParticle=hitInfo->GetMainParticle();
03483     Double_t mainX1=hitInfo->GetMainX1();
03484     Int_t muon=13;
03485 
03486     //test for straight tracks
03487     if (abs(mainParticle)==muon && 
03488         (mainX1>mainX1Cut || mainX1<-1*mainX1Cut)){
03489       straight=false;
03490       break;
03491     }
03492   }
03493 
03494   //return result
03495   return straight;
03496 }
03497 
03498 //......................................................................
03499 
03500 Int_t CDAnalysis::TrueMuonHunter(Int_t event)
03501 {
03503   if (!fTruthHitInfo) return -1;
03504 
03505   TClonesArray &cTruth = *fTruthHitInfo;
03506   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03507   
03508   Bool_t foundFirstMuon=false;
03509   Int_t firstMuonPlane=-1;
03510 
03511   //loop over the truth hits
03512   for (Int_t hit=0;hit<numTruthHits;hit++){
03513     //cast the tclonesarray up to a truthhitinfo object
03514     CDTruthHitInfo *hitInfo=
03515       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03516     
03517     Int_t plane=hitInfo->GetPlane();
03518     Double_t enDep=hitInfo->GetTotalEnDep();
03519     //Double_t earliestT1=hitInfo->GetEarliestT1();
03520     Int_t mainParticle=hitInfo->GetMainParticle();
03521     Double_t mainPartEn=hitInfo->GetMainPartEn();
03522     Int_t muon=13;
03523 
03524     if (abs(mainParticle)==muon){
03525       
03526       if (!foundFirstMuon){
03527         MSG("CDAnalysis",Msg::kInfo)
03528           <<"Event="<<event<<": First plane with muon="<<plane<<endl;
03529         firstMuonPlane=plane;
03530         foundFirstMuon=true;
03531       }
03532 
03533       if (plane>32){
03534         MSG("CDAnalysis",Msg::kInfo)
03535           <<"Plane="<<plane<<", enDep="<<enDep
03536           <<", muon energy="<<mainPartEn<<endl;
03537       }
03538     }
03539 
03540   }
03541 
03542   return firstMuonPlane;
03543 }
03544 
03545 //......................................................................
03546 
03547 Float_t CDAnalysis::TrueXInStripFrame(Int_t plane,Int_t strip,
03548                                       Int_t event) const
03549 {
03550   if (!fTruthHitInfo) return -1;
03551 
03552   static Int_t lastEvent=-1;
03553   static map<Int_t,Double_t> trueX;
03554   static map<Int_t,Int_t> counter;
03555   Int_t inStripKey=500*plane+strip;
03556 
03557   //if a new event then have to rebuild the map of x
03558   //as a function of globalstrip key
03559   if (event!=lastEvent){
03560     //set the lastevent
03561     lastEvent=event;
03562 
03563     //clear the map
03564     trueX.clear();
03565     counter.clear();
03566 
03567     //now build the new map for this event
03568 
03569     TClonesArray &cTruth = *fTruthHitInfo;
03570     Int_t numTruthHits=fTruthHitInfo->GetEntries();
03571     
03572     //loop over the truth hits
03573     for (Int_t hit=0;hit<numTruthHits;hit++){
03574       //cast the tclonesarray up to a truthhitinfo object
03575       CDTruthHitInfo *hitInfo=
03576         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03577     
03578       Int_t pmtTruth1=hitInfo->GetPmtTruth1();
03579       Int_t pmtTruth2=hitInfo->GetPmtTruth2();
03580       Int_t sumTruth=0;
03581       
03582       //add up the bits
03583       sumTruth|=pmtTruth1;
03584       sumTruth|=pmtTruth2;
03585 
03586       //check if genuine bit is set
03587       Bool_t genuineBit=((sumTruth & DigiSignal::kGenuine)==
03588                          DigiSignal::kGenuine);
03589 
03590       //if not genuine then skip this strip
03591       if (!genuineBit) {
03592         continue;
03593       }
03594 
03595       Int_t plane=hitInfo->GetPlane();
03596       Int_t strip=hitInfo->GetStrip();
03597       Int_t stripKey=500*plane+strip;
03598 
03599       Double_t mainX1=hitInfo->GetMainX1();
03600       Double_t mainX2=hitInfo->GetMainX2();
03601       Double_t avX=(mainX1+mainX2)*0.5;
03602 
03603       if (avX==0){
03604         MSG("CDAnalysis",Msg::kDebug)
03605           <<"CDAnalysis::TrueXInStripFrame::average x="<<avX
03606           <<", enDep="<<hitInfo->GetTotalEnDep()<<endl;
03607       }
03608 
03609       trueX[stripKey]=avX;
03610       counter[stripKey]++;
03611     }
03612   }
03613 
03614   if (counter[inStripKey]>0) return trueX[inStripKey];
03615   else return -1;
03616 }
03617 
03618 //......................................................................
03619 
03620 Double_t CDAnalysis::TrueEnDep(Int_t inplane,Int_t event) const
03621 {
03622   if (!fTruthHitInfo) return 0;
03623 
03624   static Int_t lastEvent=-1;
03625   static map<Int_t,Double_t> plEnDep;
03626 
03627   //if a new event then have to rebuild the map of energy dep
03628   //as a function of plane
03629   if (event!=lastEvent){
03630     //set the lastevent
03631     lastEvent=event;
03632 
03633     //clear the map
03634     plEnDep.clear();
03635 
03636     //now build the new map for this event
03637 
03638     TClonesArray &cTruth = *fTruthHitInfo;
03639     Int_t numTruthHits=fTruthHitInfo->GetEntries();
03640     
03641     //loop over the truth hits
03642     for (Int_t hit=0;hit<numTruthHits;hit++){
03643       //cast the tclonesarray up to a truthhitinfo object
03644       CDTruthHitInfo *hitInfo=
03645         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03646     
03647       Int_t plane=hitInfo->GetPlane();
03648       Double_t enDep=hitInfo->GetTotalEnDep();
03649       //Double_t earliestT1=hitInfo->GetEarliestT1();
03650 
03651       //cut out the decay electron
03652       //if (earliestT1>15e-9) continue;
03653 
03654       plEnDep[plane]+=enDep;
03655     }
03656   }
03657 
03658   return plEnDep[inplane];
03659 }
03660 
03661 //......................................................................
03662 
03663 Double_t CDAnalysis::TrueMainPL(Int_t inplane,Int_t event) const
03664 {
03665   if (!fTruthHitInfo) return 0;
03666 
03667   static Int_t lastEvent=-1;
03668   static map<Int_t,Double_t> plPL;
03669   //static map<Int_t,Int_t> plStrip;
03670 
03671   //if a new event then have to rebuild the map of energy dep
03672   //as a function of plane
03673   if (event!=lastEvent){
03674     MAXMSG("CDAnalysis",Msg::kDebug,50)
03675       <<"Building map..."<<endl;
03676     //set the lastevent
03677     lastEvent=event;
03678 
03679     //clear the map
03680     plPL.clear();
03681     //plStrip.clear();
03682 
03683     //now build the new map for this event
03684 
03685     TClonesArray &cTruth = *fTruthHitInfo;
03686     Int_t numTruthHits=fTruthHitInfo->GetEntries();
03687     
03688     //loop over the truth hits
03689     for (Int_t hit=0;hit<numTruthHits;hit++){
03690       //cast the tclonesarray up to a truthhitinfo object
03691       CDTruthHitInfo *hitInfo=
03692         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03693     
03694       Int_t plane=hitInfo->GetPlane();
03695       Int_t strip=hitInfo->GetStrip();
03696       Double_t pathLen=hitInfo->GetMainPathLength();
03697       Int_t particle=hitInfo->GetMainParticle();
03698       Int_t muon=13;
03699 
03700       if (abs(particle)!=muon) {
03701         MAXMSG("CDAnalysis",Msg::kDebug,100)
03702           <<"Not a muon so ignoring..."<<endl;
03703         continue;
03704       }
03705 
03706       MAXMSG("CDAnalysis",Msg::kDebug,500)
03707         <<"plane="<<plane//<<", lastSt="<<plStrip[plane]
03708         <<" (currSt="<<strip<<")"<<", lastPL="<<plPL[plane]*100
03709         <<", currentPL="<<pathLen*100<<endl;
03710       plPL[plane]+=pathLen;
03711       //plStrip[plane]=strip;
03712     }
03713     MAXMSG("CDAnalysis",Msg::kDebug,50)
03714       <<"Finished building map"<<endl;
03715   }
03716 
03717   return plPL[inplane];
03718 }
03719 
03720 //......................................................................
03721 
03722 Double_t CDAnalysis::GetMainParticleEnergy() const
03723 {
03724   if (!fTruthHitInfo) return 0;
03725 
03726   Double_t mainEnergy=0;
03727 
03728   TClonesArray &cTruth = *fTruthHitInfo;
03729   Int_t numTruthHits=fTruthHitInfo->GetEntries();
03730   
03731   //loop over the truth hits
03732   for (Int_t hit=0;hit<numTruthHits;hit++){
03733     //cast the tclonesarray up to a truthhitinfo object
03734     CDTruthHitInfo *hitInfo=
03735       dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
03736     
03737     Double_t en=hitInfo->GetMainPartEn();
03738 
03739     MSG("CDAnalysis",Msg::kDebug)
03740       <<"en="<<en<<endl;
03741 
03742     //find the greatest energy
03743     if (en>mainEnergy) {
03744       mainEnergy=en;
03745       MSG("CDAnalysis",Msg::kDebug)
03746         <<"mainEnergy="<<mainEnergy<<endl;
03747     }
03748   }
03749  
03750   return mainEnergy;
03751 }
03752 
03753 //......................................................................
03754 
03755 Double_t CDAnalysis::GetGreatestMainParticleEnergy(Int_t nEvents) const
03756 {
03757   Double_t mainEnergy=0;
03758 
03759   if (nEvents>fEvents) nEvents=fEvents;
03760 
03761   for(Int_t event=0;event<nEvents;event++){
03762     
03763     //get the snarl/event
03764     fTrackerTree->GetEvent(event); 
03765     
03766     Double_t mEn=this->GetMainParticleEnergy();
03767     
03768     //select the greatest one
03769     if (mEn>mainEnergy) mainEnergy=mEn;
03770   }
03771 
03772   return mainEnergy;
03773 }
03774 
03775 //......................................................................
03776 
03777 Double_t CDAnalysis::CalcMeuPLCorrected(std::map<Int_t,Float_t> plEnDep,
03778                                         std::map<Int_t,Float_t> plPLCor,
03779                                         Int_t event,
03780                                         Float_t* GeVPerMeu
03781                                         ) const
03782 {
03783   if (plEnDep.size()==0 || plPLCor.size()==0){
03784     MAXMSG("CDAnalysis",Msg::kWarning,10000)
03785       <<"Can't CalcMeuPLCorrected, map has size zero"<<endl;
03786     return -1;
03787   }
03788 
03789   Float_t local14_16=0;
03790   Float_t localSigCor=0;//for calc meu without fractions of planes
03791   Float_t localEnDep=0;//for calc meu without fractions of planes
03792   Int_t plCounter=0;
03793   Float_t initValue=-999;
03794   Float_t materialFromTrkEnd=0;
03795   Float_t materialInWindow=0;
03796   const Float_t material01Pl=(2.5+1)*Munits::cm;
03797   const Float_t material16Pl=16*material01Pl;
03798   const Float_t material14Pl=14*material01Pl;
03799   MAXMSG("CDAnalysis",Msg::kInfo,1)
03800     <<"Using 14 pls material="<<material14Pl
03801     <<", 16 plns="<<material16Pl
03802     <<", 1 plns="<<material01Pl<<endl;
03803 
03804   Int_t endPlane=this->GetEventLength();
03805 
03806   //calculate energy deposition in the window
03807   if (endPlane>=0){
03808     MAXMSG("CDAnalysis",Msg::kDebug,100)
03809       <<"Analysing track window, vtxPl=0"
03810       <<", endPl="<<endPlane<<endl;
03811     
03813     //loop over the track
03815     Int_t pl=endPlane;
03816     while (pl!=0){
03817       
03818       Float_t pathLengthCor=initValue;
03819       pathLengthCor=plPLCor[pl];
03820       if (pathLengthCor<1){
03821         MAXMSG("CDAnalysis",Msg::kWarning,1000)
03822           <<"pl="<<pl<<", endPlane="<<endPlane
03823           <<", path len cor wrong="<<pathLengthCor<<endl;
03824         //set default to 1
03825         pathLengthCor=1;
03826       }
03827 
03829       //sum up energy in window
03831       if ((materialFromTrkEnd+
03832            pathLengthCor*material01Pl)>material16Pl && 
03833           //check if window starts within or before this plane
03834           //&& that don't already have whole window of material
03835           materialInWindow<material14Pl){
03836 
03837         //alternatively start window after the plane in which 
03838         //the window should officially start part way through
03839         //if (materialFromTrkEnd>material16Pl && 
03840         //materialInWindow<material14Pl){
03841         
03842         //work out meu without using a fraction of a plane
03843         Float_t plCorEnDep=0;
03844         if (pathLengthCor) plCorEnDep=plEnDep[pl]/pathLengthCor;
03845         localSigCor+=plCorEnDep;
03846         plCounter++;
03847         //do it for the true en dep as well
03848         Float_t trueEnDep=this->TrueEnDep(pl,event);
03849         MAXMSG("CDAnalysis",Msg::kInfo,100)
03850           <<"trueEnDep="<<trueEnDep
03851           <<", PLCor="<<pathLengthCor
03852           <<", sum="<<localEnDep<<endl;
03853         if (pathLengthCor) trueEnDep/=pathLengthCor;
03854         localEnDep+=trueEnDep;
03855 
03856         //check if adding this much energy takes you over
03857         //the required amount of material
03858         if (materialInWindow+pathLengthCor*material01Pl>material14Pl){
03859 
03860           Float_t materialNeeded=material14Pl-materialInWindow;
03861           //calc the fraction of material/energy needed from this plane
03862           Float_t fractNeeded=materialNeeded/
03863             (pathLengthCor*material01Pl);
03864           
03865           MAXMSG("CDAnalysis",Msg::kDebug,100)
03866             <<"Last Chunk: matNeed="<<materialNeeded
03867             <<", matPl="<<pathLengthCor*material01Pl
03868             <<", 14Pl="<<material14Pl
03869             <<", matWin="<<materialInWindow
03870             <<", matTrk="<<materialFromTrkEnd<<endl
03871             <<"fractNeeded="<<fractNeeded<<", en in plane="<<plEnDep[pl]
03872             <<", en used="<<fractNeeded*plEnDep[pl]<<endl;
03873 
03874           //increment the material in window
03875           materialInWindow+=fractNeeded*(pathLengthCor*material01Pl);
03876 
03877           //add the required fraction of energy in this plane to
03878           //the total
03879           local14_16+=fractNeeded*plEnDep[pl];
03880         }
03881         else{
03882           //add the energy in this plane to the total
03883           materialInWindow+=pathLengthCor*material01Pl;
03884 
03885           MAXMSG("CDAnalysis",Msg::kDebug,500)
03886             <<"Window:p="<<pl
03887             <<", matPl="<<pathLengthCor*material01Pl
03888             <<", matWin="<<materialInWindow
03889             <<", matTrk="<<materialFromTrkEnd
03890             <<", plEn="<<plEnDep[pl]
03891             <<endl;
03892 
03893           //increment the energy deposited
03894           local14_16+=plEnDep[pl];
03895         }
03896       }
03897 
03898       MAXMSG("CDAnalysis",Msg::kDebug,1000)
03899         <<"local: matPl="<<pathLengthCor*material01Pl
03900         <<", matTrk="<<materialFromTrkEnd
03901         <<", matWin="<<materialInWindow<<", sumEnDep="<<local14_16
03902         <<"PLCor="<<pathLengthCor
03903         <<endl;
03904 
03905       //sum up material traversed
03906       if (pathLengthCor>0) materialFromTrkEnd+=pathLengthCor*
03907                              material01Pl;
03908       else {
03909         MAXMSG("CDAnalysis",Msg::kInfo,1000)
03910           <<"Ahhh path len cor wrong="<<pathLengthCor<<endl;
03911       }
03912 
03913       //increment the plane
03914       pl--;
03915     }
03916   }
03917 
03918   Float_t winSigCor=0;
03919   if (plCounter){
03920     winSigCor=localSigCor/plCounter;
03921     localEnDep/=plCounter;
03922     //set the output variable
03923     if (GeVPerMeu) *GeVPerMeu=localEnDep;
03924   }
03925 
03926   //meu from fraction of last plane in window
03927   local14_16/=14;
03928 
03929   //decide which to use
03930   Float_t meu=local14_16;
03931   Bool_t useNoFraction=true;
03932   if (useNoFraction) meu=winSigCor;
03933 
03934   //calc fraction of material in window actually obtained
03935   Float_t fractWin=materialInWindow/material14Pl;
03936   
03937   MAXMSG("CDAnalysis",Msg::kInfo,500)
03938     <<"14_16="<<local14_16<<", winSigCor="<<winSigCor
03939     <<", plCounter="<<plCounter<<", fractWin="<<fractWin<<endl;
03940 
03941   //don't return meu when only a fraction of window was obtained
03942   if (fractWin<1) meu=-1;
03943 
03944   return meu;
03945 }
03946 
03947 //......................................................................
03948 
03949 void CDAnalysis::FillEnVsDist(std::map<Int_t,Float_t> plEnDep,
03950                               std::map<Int_t,Float_t> plPLCor,
03951                               Int_t event) const
03952 {
03953   if (plEnDep.size()==0 || plPLCor.size()==0){
03954     MAXMSG("CDAnalysis",Msg::kWarning,10000)
03955       <<"Can't FillEnVsDist, map has size zero"<<endl;
03956     return;
03957   }
03958 
03959   Float_t materialFromTrkEnd=0;
03960   Float_t trueMaterialFromTrkEnd=0;
03961   Int_t planesFromTrkEnd=0;
03962   const Float_t material01Pl=(5.94)*Munits::cm;//including air gap
03963   Float_t initValue=-999;
03964   
03965   
03966   //static Int_t event=-999;
03967   map<Int_t,Float_t> truePLCor;
03968   this->TruePLCor(truePLCor,event);
03969   //event++;
03970 
03971   static TProfile* pEnVsDist=0;
03972   static TProfile* pEnVsDistAll=0;
03973   static TProfile* pEnVsDistAll2=0;
03974   static TProfile* pEnVsDist0=0;
03975   static TProfile* pTrueEnVsDist0=0;
03976   static TProfile* pTrueEnPLCVsDist0=0;
03977   static TProfile* pTrueEnPLCVsDist0270=0;
03978   static TProfile* pTrueEnPLCVsDist0290=0;
03979   static TProfile* pTrueEnPLCVsDist0310=0;
03980   static TProfile* pEnVsPlane0=0;
03981   static TProfile* pTrueEnVsPlane0=0;
03982   static TProfile* pEnVsDistNoEnd=0;
03983   static TProfile* pEnVsDistNoEnd4951=0;
03984   static TProfile* pEnVsDistNoEnd40=0;
03985   static TProfile* pEnVsDistNoEnd250=0;
03986   static TProfile* pEnVsDistNoEnd270=0;
03987   static TProfile* pEnVsDistNoEnd290=0;
03988   static TProfile* pEnVsDistNoEnd290a=0;
03989   static TProfile* pEnVsDistNoEnd290b=0;
03990   static TProfile* pEnVsDistNoEnd310=0;
03991   static TProfile* pEnVsDistNoEndTrue=0;
03992   static TProfile* pEnVsDistNoEndTrue2=0;
03993   static TProfile* pPLCorVsPlane290=0;
03994   static TProfile* pPLCorVsPlaneTrue=0;
03995   static TH1F* hMatFromTrkEnd=0;
03996   static TH1F* hMatFromTrkEndTrue=0;
03997   static TH1F* hSigCorPLC=0;
03998 
03999   static vector<TH1F*> meuSigCorNoPLCorHistos(60);
04000   static vector<TH1F*> meuSigCorPLCorHistos(60);
04001   static vector<TH1F*> meuSigCorNoPLCorPerpHistos(60);
04002   static vector<TH1F*> meuSigCorPLCorPerpHistos(60);
04003   static vector<TH1F*> meuSigCorNoPLCorZerosHistos(60);
04004   static vector<TH1F*> meuSigCorPLCorZerosHistos(60);
04005 
04006   if (pEnVsDist==0) {
04007     pEnVsDist=new TProfile("pEnVsDist","pEnVsDist",60,0,
04008                            (60*material01Pl)/Munits::cm);
04009     pEnVsDistAll=new TProfile("pEnVsDistAll","pEnVsDistAll",60,0,
04010                               (60*material01Pl)/Munits::cm);
04011     pEnVsDistAll2=new TProfile("pEnVsDistAll2","pEnVsDistAll2",60,0,
04012                                (60*material01Pl)/Munits::cm);
04013     pEnVsDistNoEnd=new TProfile("pEnVsDistNoEnd","pEnVsDistNoEnd",60,0,
04014                                 (60*material01Pl)/Munits::cm);
04015     pEnVsDist0=new TProfile("pEnVsDist0","pEnVsDist0",60,0,
04016                             (60*material01Pl)/Munits::cm);
04017     pEnVsPlane0=new TProfile("pEnVsPlane0","pEnVsPlane0",60,0,60);
04018     pTrueEnVsDist0=new TProfile("pTrueEnVsDist0","pTrueEnVsDist0",60,0,
04019                                 (60*material01Pl)/Munits::cm);
04020     pTrueEnPLCVsDist0=new TProfile("pTrueEnPLCVsDist0",
04021                                    "pTrueEnPLCVsDist0",
04022                                    60,0,(60*material01Pl)/Munits::cm);
04023     pTrueEnPLCVsDist0270=new TProfile("pTrueEnPLCVsDist0270",
04024                                    "pTrueEnPLCVsDist0270",
04025                                    60,0,(60*material01Pl)/Munits::cm);
04026     pTrueEnPLCVsDist0290=new TProfile("pTrueEnPLCVsDist0290",
04027                                    "pTrueEnPLCVsDist0290",
04028                                    60,0,(60*material01Pl)/Munits::cm);
04029     pTrueEnPLCVsDist0310=new TProfile("pTrueEnPLCVsDist0310",
04030                                    "pTrueEnPLCVsDist0310",
04031                                    60,0,(60*material01Pl)/Munits::cm);
04032     pTrueEnVsPlane0=new TProfile("pTrueEnVsPlane0","pTrueEnVsPlane0",
04033                                  60,0,60);
04034     pEnVsDistNoEnd4951=new TProfile("pEnVsDistNoEnd4951",
04035                                     "pEnVsDistNoEnd4951",60,0,
04036                                     (60*material01Pl)/Munits::cm);
04037     pEnVsDistNoEnd40=new TProfile("pEnVsDistNoEnd40",
04038                                   "pEnVsDistNoEnd40",60,0,
04039                                   (60*material01Pl)/Munits::cm);
04040     pEnVsDistNoEnd250=new TProfile("pEnVsDistNoEnd250",
04041                                    "pEnVsDistNoEnd250",60,0,
04042                                    (60*material01Pl)/Munits::cm);
04043     pEnVsDistNoEnd270=new TProfile("pEnVsDistNoEnd270",
04044                                    "pEnVsDistNoEnd270",60,0,
04045                                    (60*material01Pl)/Munits::cm);
04046     pEnVsDistNoEnd290=new TProfile("pEnVsDistNoEnd290",
04047                                    "pEnVsDistNoEnd290",60,0,
04048                                    (60*material01Pl)/Munits::cm);
04049     pEnVsDistNoEnd290a=new TProfile("pEnVsDistNoEnd290a",
04050                                    "pEnVsDistNoEnd290a",60,0,
04051                                   (60*material01Pl)/Munits::cm);
04052     pEnVsDistNoEnd290b=new TProfile("pEnVsDistNoEnd290b",
04053                                    "pEnVsDistNoEnd290b",60,0,
04054                                   (60*material01Pl)/Munits::cm);
04055     pEnVsDistNoEnd310=new TProfile("pEnVsDistNoEnd310",
04056                                    "pEnVsDistNoEnd310",60,0,
04057                                    (60*material01Pl)/Munits::cm);
04058     pEnVsDistNoEndTrue=new TProfile("pEnVsDistNoEndTrue",
04059                                     "pEnVsDistNoEndTrue",60,0,
04060                                     (60*material01Pl)/Munits::cm);
04061     pEnVsDistNoEndTrue2=new TProfile("pEnVsDistNoEndTrue2",
04062                                      "pEnVsDistNoEndTrue2",60,0,
04063                                      (60*material01Pl)/Munits::cm);
04064     hMatFromTrkEnd=new TH1F("hMatFromTrkEnd","hMatFromTrkEnd",200,0,4);
04065     hMatFromTrkEndTrue=new TH1F("hMatFromTrkEndTrue",
04066                                 "hMatFromTrkEndTrue",200,0,4);
04067     hSigCorPLC=new TH1F("hSigCorPLC","hSigCorPLC",5000,-100,20000);
04068     pPLCorVsPlane290=new TProfile("pPLCorVsPlane290",
04069                                   "pPLCorVsPlane290",60,0,60);
04070     pPLCorVsPlaneTrue=new TProfile("pPLCorVsPlaneTrue",
04071                                    "pPLCorVsPlaneTrue",60,0,60);
04072 
04073     for (Int_t i=0;i<60;i++){
04074       string sNameSigCorNoPLCor="hMeuSigCorNoPLCorPlane";
04075       string sNameSigCorPLCor="hMeuSigCorPLCorPlane";
04076       string sNameSigCorNoPLCorPerp="hMeuSigCorNoPLCorPerpPlane";
04077       string sNameSigCorPLCorPerp="hMeuSigCorPLCorPerpPlane";
04078       string sNameSigCorNoPLCorZeros="hMeuSigCorNoPLCorZerosPlane";
04079       string sNameSigCorPLCorZeros="hMeuSigCorPLCorZerosPlane";
04080       //string sNameAdc="hAdcNoPLCorPlane";
04081       string sNum=Form("%d",i);
04082       sNameSigCorNoPLCor+=sNum;
04083       sNameSigCorPLCor+=sNum;
04084       sNameSigCorNoPLCorPerp+=sNum;
04085       sNameSigCorPLCorPerp+=sNum;
04086       sNameSigCorNoPLCorZeros+=sNum;
04087       sNameSigCorPLCorZeros+=sNum;
04088       
04089       meuSigCorNoPLCorHistos[i]=new TH1F
04090         (sNameSigCorNoPLCor.c_str(),sNameSigCorNoPLCor.c_str(),
04091          300,-2,3000);
04092       meuSigCorPLCorHistos[i]=new TH1F
04093         (sNameSigCorPLCor.c_str(),sNameSigCorPLCor.c_str(),
04094          300,-2,3000);
04095 
04096       meuSigCorNoPLCorPerpHistos[i]=new TH1F
04097         (sNameSigCorNoPLCorPerp.c_str(),sNameSigCorNoPLCorPerp.c_str(),
04098          300,-2,3000);
04099       meuSigCorPLCorPerpHistos[i]=new TH1F
04100         (sNameSigCorPLCorPerp.c_str(),sNameSigCorPLCorPerp.c_str(),
04101          300,-2,3000);
04102       
04103       meuSigCorNoPLCorZerosHistos[i]=new TH1F
04104         (sNameSigCorNoPLCorZeros.c_str(),
04105          sNameSigCorNoPLCorZeros.c_str(),
04106          300,-2,3000);
04107       meuSigCorPLCorZerosHistos[i]=new TH1F
04108         (sNameSigCorPLCorZeros.c_str(),
04109          sNameSigCorPLCorZeros.c_str(),
04110          300,-2,3000);
04111     }
04112 
04113     MSG("CDAnalysis",Msg::kInfo)
04114       <<"Creating TProfile, pEnVsDist, max bin="
04115       <<(60*material01Pl)/Munits::cm<<endl;
04116   }
04117 
04118   //Int_t endPlane=this->GetEventLength();
04119   Int_t endPlane=this->CalcLastPlaneOnTrkNoXTalk();
04120   Int_t planeToStopBefore=0;//have to change length cuts too!!!
04121 
04122   //calculate energy deposition in the window
04123   if (endPlane>=0){
04124     MAXMSG("CDAnalysis",Msg::kInfo,100)
04125       <<"Filling histo, vtxPl=0"
04126       <<", endPl="<<endPlane<<endl;
04127     
04129     //loop over the track
04131     Int_t pl=endPlane;
04132     while (pl!=planeToStopBefore){//cut out the first x planes (en dep is low, !d-ray)
04133       
04134       Float_t pathLengthCor=initValue;
04135       pathLengthCor=plPLCor[pl];
04136       Float_t truePathLengthCor=truePLCor[pl];
04137       //might be beyond plane end so use reco PLCor
04138       if (truePathLengthCor<1) truePathLengthCor=pathLengthCor;
04139       if (pl==endPlane){
04140         //cap the very last plane
04141         if (truePathLengthCor>3) {
04142           MAXMSG("CDAnalysis",Msg::kWarning,1000)
04143             <<"Capping the last plane PLCor"<<endl;
04144           truePathLengthCor=3;
04145         }
04146       }
04147 
04148       if (pathLengthCor<1){
04149         MAXMSG("CDAnalysis",Msg::kWarning,1000)
04150           <<"pl="<<pl<<", endPlane="<<endPlane
04151           <<", path len cor wrong="<<pathLengthCor<<endl;
04152         //set default to 1
04153         pathLengthCor=1;
04154       }
04155 
04156       Float_t meuSigCor=0;
04157       if (pathLengthCor) meuSigCor=plEnDep[pl]/pathLengthCor;
04158       Float_t meuSigCorTrue=0;
04159       if (truePathLengthCor) meuSigCorTrue=plEnDep[pl]/
04160                                truePathLengthCor;
04161       Float_t plMaterial=pathLengthCor*material01Pl;
04162       Float_t truePlMaterial=truePathLengthCor*material01Pl;
04163 
04164       //plot the value half way through the range of dE/dx it 
04165       //effectively integrates over
04166       Float_t toPlotMaterial=plMaterial*0.5+materialFromTrkEnd;
04167       Float_t trueToPlotMaterial=truePlMaterial*0.5+
04168         trueMaterialFromTrkEnd;
04169 
04170       Float_t trueEnDep=this->TrueEnDep(pl,event);
04171       Float_t trueEnDepPLC=-1;
04172       if (truePathLengthCor) {
04173         trueEnDepPLC=trueEnDep/truePathLengthCor;
04174       }
04175       
04176       //fill the histograms for each individual plane
04177       if (pl<60 && pl>=0) {
04178         //fill both with and without the pathlength correction
04179         //fill as a function of planes from track end point
04180         meuSigCorNoPLCorHistos[planesFromTrkEnd]->Fill(plEnDep[pl]);
04181         meuSigCorPLCorHistos[planesFromTrkEnd]->Fill(meuSigCor);
04182 
04183         //fill as a function of distance from track end point
04184         //distance in units of "perpendicular planes"
04185         Int_t planesFromTrkEndPerp=
04186           static_cast<Int_t>(materialFromTrkEnd/material01Pl);
04187         MAXMSG("CDAnalysis",Msg::kInfo,1000)
04188           <<"pl="<<pl<<", endPlane="<<endPlane
04189           <<", plFrTrkEnd="<<planesFromTrkEnd
04190           <<", plFrTrkEndPerp="<<planesFromTrkEndPerp
04191           <<", matFrTrkEnd="<<materialFromTrkEnd
04192           <<", material01Pl="<<material01Pl<<endl;
04193         if (planesFromTrkEndPerp<60 && planesFromTrkEndPerp>=0) {
04194           meuSigCorNoPLCorPerpHistos[planesFromTrkEndPerp]->
04195             Fill(plEnDep[pl]);
04196           meuSigCorPLCorPerpHistos[planesFromTrkEndPerp]->
04197             Fill(meuSigCor);
04198         }
04199         else cout<<"ahhh, planesFromTrkEndPerp="
04200                  <<planesFromTrkEndPerp<<endl;
04201 
04202         //fill as a function of plane number
04203         meuSigCorNoPLCorZerosHistos[pl]->Fill(plEnDep[pl]);
04204         meuSigCorPLCorZerosHistos[pl]->Fill(meuSigCor);
04205       }
04206       else cout<<"ahhh, pl="<<pl<<endl;
04207 
04208       //fill plot of PLC energy deposition
04209       hSigCorPLC->Fill(meuSigCor);
04210       pEnVsDistAll->Fill((materialFromTrkEnd/Munits::cm),meuSigCor);
04211       if (meuSigCor<7000) pEnVsDistAll2->Fill
04212                             ((materialFromTrkEnd/Munits::cm),meuSigCor);
04213 
04214       //put a check on the crazy brems
04215       //can get high landau-tail events in individual planes
04216       if (meuSigCor<5000){
04217         pEnVsDist->Fill((toPlotMaterial/Munits::cm),meuSigCor);
04218         
04219         //fill using 0 for the first pl, 
04220         //don't try and get an average position
04221         pEnVsDist0->Fill((materialFromTrkEnd/Munits::cm),meuSigCor);
04222         pEnVsPlane0->Fill(pl,meuSigCor);
04223         pTrueEnVsDist0->Fill((materialFromTrkEnd/Munits::cm),trueEnDep);
04224         pTrueEnPLCVsDist0->Fill((materialFromTrkEnd/Munits::cm),
04225                                 trueEnDepPLC);
04226         pTrueEnVsPlane0->Fill(pl,trueEnDep);
04227         
04228         if (pl!=endPlane) {
04229           pEnVsDistNoEnd->Fill((toPlotMaterial/Munits::cm),meuSigCor);
04230           if (truePLCor.size()>0){
04231             pEnVsDistNoEndTrue->Fill((trueToPlotMaterial/Munits::cm),
04232                                      meuSigCorTrue);
04233             //make one with same positions as reco but true enDep
04234             pEnVsDistNoEndTrue2->Fill((toPlotMaterial/Munits::cm),
04235                                       meuSigCorTrue);
04236           }
04237         }
04238       }
04239 
04240       if (meuSigCor<5000 && endPlane>=49 && endPlane<=51){
04241         if (pl!=endPlane) {
04242           pEnVsDistNoEnd4951->Fill((toPlotMaterial/Munits::cm),
04243                                    meuSigCor);
04244         }
04245       }
04246 
04247       if (meuSigCor<5000 && endPlane>40){
04248         if (pl!=endPlane) {
04249           pEnVsDistNoEnd40->Fill((toPlotMaterial/Munits::cm),
04250                                  meuSigCor);
04251         }
04252       }
04253 
04254       //sum up material traversed
04255       materialFromTrkEnd+=plMaterial;
04256       trueMaterialFromTrkEnd+=truePlMaterial;
04257       planesFromTrkEnd++;
04258 
04259       MAXMSG("CDAnalysis",Msg::kInfo,500)
04260         <<"Window:p="<<pl
04261         <<", matPl="<<pathLengthCor*material01Pl
04262         <<", matTrk="<<materialFromTrkEnd
04263         <<", plEn="<<plEnDep[pl]
04264         <<endl;
04265 
04266       //increment the plane
04267       pl--;
04268     }
04269     hMatFromTrkEnd->Fill(materialFromTrkEnd);
04270     hMatFromTrkEndTrue->Fill(trueMaterialFromTrkEnd);
04271     Float_t totalMaterial=materialFromTrkEnd;
04272     materialFromTrkEnd=0;
04273     trueMaterialFromTrkEnd=0;
04274     
04276     //2nd loop over the track
04278     pl=endPlane;
04279     while (pl!=planeToStopBefore){//cut out the first x planes (en dep is low, !d-ray)
04280       
04281       Float_t pathLengthCor=initValue;
04282       pathLengthCor=plPLCor[pl];
04283       Float_t truePathLengthCor=truePLCor[pl];
04284       //might be beyond plane end so use reco PLCor
04285       if (truePathLengthCor<1) truePathLengthCor=pathLengthCor;
04286       if (pl==endPlane){
04287         //cap the very last plane
04288         if (truePathLengthCor>3) {
04289           MAXMSG("CDAnalysis",Msg::kWarning,1000)
04290             <<"Capping the last plane PLCor"<<endl;
04291           truePathLengthCor=3;
04292         }
04293       }
04294 
04295       if (pathLengthCor<1){
04296         MAXMSG("CDAnalysis",Msg::kWarning,1000)
04297           <<"pl="<<pl<<", endPlane="<<endPlane
04298           <<", path len cor wrong="<<pathLengthCor<<endl;
04299         //set default to 1
04300         pathLengthCor=1;
04301       }
04302 
04303       Float_t meuSigCor=0;
04304       if (pathLengthCor) meuSigCor=plEnDep[pl]/pathLengthCor;
04305       Float_t meuSigCorTrue=0;
04306       if (truePathLengthCor) meuSigCorTrue=plEnDep[pl]/
04307                                truePathLengthCor;
04308       Float_t plMaterial=pathLengthCor*material01Pl;
04309       Float_t truePlMaterial=truePathLengthCor*material01Pl;
04310 
04311       //plot the value half way through the range of dE/dx it 
04312       //effectively integrates over
04313       Float_t toPlotMaterial=plMaterial*0.5+materialFromTrkEnd;
04314       //Float_t trueToPlotMaterial=truePlMaterial*0.5+
04315       //trueMaterialFromTrkEnd;
04316 
04317       Float_t trueEnDep=this->TrueEnDep(pl,event);
04318       Float_t trueEnDepPLC=-1;
04319       if (truePathLengthCor) {
04320         trueEnDepPLC=trueEnDep/truePathLengthCor;
04321       }
04322 
04323       //put a check on the crazy brems and cut out the really steep ones
04324       //can also get high landau-tail events in individual planes
04325       if (meuSigCor<5000 && totalMaterial>2.49 && totalMaterial<2.61){
04326         if (pl!=endPlane) {
04327           pEnVsDistNoEnd250->Fill((toPlotMaterial/Munits::cm),
04328                                   meuSigCor);
04329         }
04330       }
04331       if (meuSigCor<5000 && totalMaterial>2.7 && totalMaterial<2.9){
04332         if (pl!=endPlane) {
04333           pEnVsDistNoEnd270->Fill((toPlotMaterial/Munits::cm),
04334                                   meuSigCor);
04335           pTrueEnPLCVsDist0270->Fill((materialFromTrkEnd/Munits::cm),
04336                                      trueEnDepPLC);
04337         }
04338       }
04339       //was 2.8->3.0 when pl!=1
04340       if (meuSigCor<5000 && totalMaterial>2.9 && totalMaterial<3.1){
04341         if (pl!=endPlane) {
04342           pPLCorVsPlane290->Fill(pl,pathLengthCor);
04343           pTrueEnPLCVsDist0290->Fill((materialFromTrkEnd/Munits::cm),
04344                                      trueEnDepPLC);
04345           pPLCorVsPlaneTrue->Fill(pl,truePathLengthCor);
04346           pEnVsDistNoEnd290->Fill((toPlotMaterial/Munits::cm),
04347                                   meuSigCor);
04348         }
04349       }
04350       if (meuSigCor<5000 && totalMaterial>3.1 && totalMaterial<3.3){
04351         if (pl!=endPlane) {
04352           pEnVsDistNoEnd310->Fill((toPlotMaterial/Munits::cm),
04353                                   meuSigCor);
04354           pTrueEnPLCVsDist0310->Fill((materialFromTrkEnd/Munits::cm),
04355                                      trueEnDepPLC);
04356         }
04357       }
04358 
04359       if (meuSigCor<5000 && totalMaterial>2.95 && totalMaterial<3.05){
04360         if (pl!=endPlane) {
04361           pEnVsDistNoEnd290a->Fill((toPlotMaterial/Munits::cm),
04362                                    meuSigCor);
04363         }
04364       }
04365 
04366 
04367       if (meuSigCor<5000 && totalMaterial>2.96 && totalMaterial<3.03){
04368         if (pl!=endPlane) {
04369           pEnVsDistNoEnd290b->Fill((toPlotMaterial/Munits::cm),
04370                                   meuSigCor);
04371         }
04372       }
04373 
04374       //sum up material traversed
04375       materialFromTrkEnd+=plMaterial;
04376       trueMaterialFromTrkEnd+=truePlMaterial;
04377 
04378       //increment the plane
04379       pl--;
04380     }
04381   }
04382 }
04383 
04384 //......................................................................
04385 
04386 Double_t CDAnalysis::TrueEnDepNotSc(Int_t inplane,Int_t event) const
04387 {
04388   if (!fTruthHitInfo) return 0;
04389 
04390   static Int_t lastEvent=-1;
04391   static map<Int_t,Double_t> plEnDep;
04392   static map<Int_t,Double_t> plMainPartEn;
04393   static Double_t totalEnDep=0;
04394 
04395   //if a new event then have to rebuild the map of energy dep
04396   //as a function of plane
04397   if (event!=lastEvent){
04398 
04399     MSG("CDAnalysis",Msg::kVerbose) 
04400       <<"Clearing the maps..."<<endl;
04401 
04402     //set the lastevent
04403     lastEvent=event;
04404 
04405     //clear the map
04406     plEnDep.clear();
04407     plMainPartEn.clear();
04408     totalEnDep=0;
04409 
04410     //now build the new map for this event
04411 
04412     TClonesArray &cTruth = *fTruthHitInfo;
04413     Int_t numTruthHits=fTruthHitInfo->GetEntries();
04414     
04415     //loop over the truth hits
04416     for (Int_t hit=0;hit<numTruthHits;hit++){
04417       //cast the tclonesarray up to a truthhitinfo object
04418       CDTruthHitInfo *hitInfo=
04419         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
04420     
04421       Int_t plane=hitInfo->GetPlane();
04422       Int_t mainParticle=hitInfo->GetMainParticle();
04423       Double_t enDep=hitInfo->GetTotalEnDep();
04424       Double_t mainPartEn=hitInfo->GetMainPartEn();
04425       //Double_t earliestT1=hitInfo->GetEarliestT1();
04426       Int_t muon=13;
04427 
04428       //cut out the decay electron
04429       //if (earliestT1>15e-9) continue;
04430 
04431       plEnDep[plane]+=enDep;
04432       //select the biggest mainPartEn
04433       if (mainPartEn>plMainPartEn[plane] && abs(mainParticle)==muon){
04434         plMainPartEn[plane]=mainPartEn;      
04435       }
04436     }
04437   }
04438 
04439   Double_t plEnDepNotSc=0;
04440     
04441   if (!(plMainPartEn[inplane]==0 || plMainPartEn[inplane+1]==0)) {
04442     plEnDepNotSc=plMainPartEn[inplane]-plEnDep[inplane]-
04443       plMainPartEn[inplane+1];
04444     totalEnDep+=plEnDep[inplane]+plEnDepNotSc;
04445   }
04446 
04447   MSG("CDAnalysis",Msg::kVerbose) 
04448     <<"pl="<<inplane<<", pEn="<<plMainPartEn[inplane]
04449     <<", pEn+1="<<plMainPartEn[inplane+1]
04450     <<", eDep="<<1000*plEnDep[inplane]
04451     <<", eDepNotSc="<<1000*plEnDepNotSc
04452     <<", tE="<<totalEnDep
04453     <<endl;
04454 
04455   return plEnDepNotSc;
04456 }
04457 
04458 //......................................................................
04459 
04460 Int_t CDAnalysis::TrueNumDigiScintHits(Int_t inplane,
04461                                           Int_t event) const
04462 {
04463   if (!fTruthHitInfo) return 0;
04464 
04465   static Int_t lastEvent=-1;
04466   static map<Int_t,Int_t> numHits;
04467 
04468   //if a new event then have to rebuild the map of hits
04469   //as a function of plane
04470   if (event!=lastEvent){
04471     //set the lastevent
04472     lastEvent=event;
04473 
04474     //clear the map
04475     numHits.clear();
04476 
04477     //now build the new map for this event
04478 
04479     TClonesArray &cTruth = *fTruthHitInfo;
04480     Int_t numTruthHits=fTruthHitInfo->GetEntries();
04481     
04482     //loop over the truth hits
04483     for (Int_t hit=0;hit<numTruthHits;hit++){
04484       //cast the tclonesarray up to a truthhitinfo object
04485       CDTruthHitInfo *hitInfo=
04486         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
04487     
04488       Int_t plane=hitInfo->GetPlane();
04489       Int_t numDsh=hitInfo->GetNumDigiScintHits();
04490       //Double_t earliestT1=hitInfo->GetEarliestT1();
04491 
04492       //cut out the decay electron
04493       //if (earliestT1>15e-9) continue;
04494 
04495       numHits[plane]+=numDsh;
04496     }
04497   }
04498 
04499   return numHits[inplane];
04500 }
04501 
04502 //......................................................................
04503 
04504 void CDAnalysis::TruthEnDepFe()
04505 {
04506   map<Int_t,Double_t> plEnDep;
04507   map<Int_t,Double_t> plMainPartEn;
04508   Double_t totalEnDep=0;
04509   vector<TH1F*> hEnDepFe;
04510 
04511   for (Int_t pl=0;pl<60;pl++){
04512     fS="Energy Deposition in Iron, plane=";
04513     string sPl=Form("%d",pl);
04514     fS+=sPl;
04515     hEnDepFe.push_back(new TH1F(fS.c_str(),fS.c_str(),600,-2,200));
04516   }
04517 
04521   
04522   this->InitialiseLoopVariables();  
04523   
04524   for(Int_t event=0;event<fEvents;event++){
04525     
04526     this->SetLoopVariables(event);
04527     
04528     //clear the map
04529     plEnDep.clear();
04530     plMainPartEn.clear();
04531     totalEnDep=0;
04532     
04533     //now build the new map for this event
04534 
04535     if (!fTruthHitInfo) break;
04536 
04537     TClonesArray &cTruth = *fTruthHitInfo;
04538     Int_t numTruthHits=fTruthHitInfo->GetEntries();
04539     
04540     //loop over the truth hits
04541     for (Int_t hit=0;hit<numTruthHits;hit++){
04542       //cast the tclonesarray up to a truthhitinfo object
04543       CDTruthHitInfo *hitInfo=
04544         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
04545     
04546       Int_t plane=hitInfo->GetPlane();
04547       Int_t mainParticle=hitInfo->GetMainParticle();
04548       Double_t enDep=hitInfo->GetTotalEnDep();
04549       Double_t mainPartEn=hitInfo->GetMainPartEn();
04550       Double_t earliestT1=hitInfo->GetEarliestT1();
04551       Int_t muon=13;
04552 
04553       //cut out the decay electron
04554       if (earliestT1>15e-9) continue;
04555       cout<<"Cutting out the decay electron"<<endl;
04556 
04557       plEnDep[plane]+=enDep;
04558       //select the biggest mainPartEn
04559       if (mainPartEn>plMainPartEn[plane] && abs(mainParticle)==muon){
04560         plMainPartEn[plane]=mainPartEn;      
04561       }
04562     }
04563 
04564     
04565     //vector<Double_t> plEnDepFe(60);
04566 
04567     //loop 60-1 planes
04568     for (Int_t p=0;p<59;p++){
04569 
04570       Double_t plEnDepFe=plMainPartEn[p]-plEnDep[p]-
04571         plMainPartEn[p+1];
04572       totalEnDep+=plEnDep[p]+plEnDepFe;
04573       
04574       //fill the histo
04575       hEnDepFe[p]->Fill(1000*plEnDepFe);
04576       
04577       MSG("CDAnalysis",Msg::kVerbose) 
04578         <<"pl="<<p<<", pEn="<<plMainPartEn[p]
04579         <<", pEn+1="<<plMainPartEn[p+1]
04580         <<", eDep="<<1000*plEnDep[p]
04581         <<", eDepFe="<<1000*plEnDepFe
04582         <<", tE="<<totalEnDep
04583         <<endl;
04584       
04585     }
04586   }//end of for
04587 
04588   TCanvas *cEnDep=new TCanvas("cEnDep","EnDep",0,0,1200,800);
04589   cEnDep->SetFillColor(0);
04590   cEnDep->Divide(2,3);
04591   cEnDep->cd(1);
04592   hEnDepFe[0]->Draw();
04593   cEnDep->cd(2);
04594   hEnDepFe[1]->Draw();
04595   cEnDep->cd(3);
04596   hEnDepFe[2]->Draw();
04597   cEnDep->cd(4);
04598   hEnDepFe[3]->Draw();
04599   cEnDep->cd(5);
04600   hEnDepFe[4]->Draw();
04601   cEnDep->cd(6);
04602   hEnDepFe[5]->Draw();
04603 
04604 }
04605 
04606 //......................................................................
04607 
04608 void CDAnalysis::TruthEventLength()
04609 {
04610   //only have pid for real data so return if not data
04611   //if (fSimFlag!=SimFlag::kData) abort(true);
04612 
04613   //open the output file for the histograms
04614   fOutFile=this->OpenFile(fRunNumber,"EvLen");
04615 
04616   TH1F *hEventLength=new TH1F("hEventLength","EventLength hit",
04617                               77,-2,75);
04618   hEventLength->GetXaxis()->SetTitle("Event Length (planes)");
04619   hEventLength->GetXaxis()->CenterTitle();
04620   hEventLength->GetYaxis()->SetTitle("");
04621   hEventLength->GetYaxis()->CenterTitle();
04622   hEventLength->SetFillColor(0);
04623   hEventLength->SetBit(TH1::kCanRebin);
04624 
04625   TH1F *hEventLength2=new TH1F("hEventLength2","EventLength",77,-2,75);
04626   hEventLength2->GetXaxis()->SetTitle("Event Length (planes)");
04627   hEventLength2->GetXaxis()->CenterTitle();
04628   hEventLength2->GetYaxis()->SetTitle("");
04629   hEventLength2->GetYaxis()->CenterTitle();
04630   hEventLength2->SetFillColor(0);
04631   hEventLength2->SetBit(TH1::kCanRebin);
04632 
04633   TH1F *hEventLength3=new TH1F("hEventLength3","EventLength",77,-2,75);
04634   hEventLength3->GetXaxis()->SetTitle("Event Length (planes)");
04635   hEventLength3->GetXaxis()->CenterTitle();
04636   hEventLength3->GetYaxis()->SetTitle("");
04637   hEventLength3->GetYaxis()->CenterTitle();
04638   hEventLength3->SetFillColor(0);
04639   hEventLength3->SetBit(TH1::kCanRebin);
04640 
04641   TH1F *hEventLength4=new TH1F("hEventLength4","EventLength",77,-2,75);
04642   hEventLength4->GetXaxis()->SetTitle("Event Length (planes)");
04643   hEventLength4->GetXaxis()->CenterTitle();
04644   hEventLength4->GetYaxis()->SetTitle("");
04645   hEventLength4->GetYaxis()->CenterTitle();
04646   hEventLength4->SetFillColor(0);
04647   hEventLength4->SetBit(TH1::kCanRebin);
04648 
04652   
04653   this->InitialiseLoopVariables();  
04654   
04655   for(Int_t event=0;event<fEvents;event++){
04656     
04657     this->SetLoopVariables(event);
04658     
04659     Int_t overallLastPlane=0;
04660     Int_t notNoiseLastPlane=0;
04661     Int_t particleLastPlane=0;
04662     //Int_t inTimeLastPlane=0;
04663     Int_t muonLastPlane=0;
04664     
04665     if (!fTruthHitInfo) break;
04666     TClonesArray &cTruth = *fTruthHitInfo;
04667     Int_t numTruthHits=fTruthHitInfo->GetEntries();
04668 
04669     //loop over the truth hits
04670     for (Int_t hit=0;hit<numTruthHits;hit++){
04671       //cast the tclonesarray up to a truthhitinfo object
04672       CDTruthHitInfo *hitInfo=
04673         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
04674     
04675       Int_t plane=hitInfo->GetPlane();
04676       Int_t mainParticle=hitInfo->GetMainParticle();
04677       Int_t pmtTruth1=hitInfo->GetPmtTruth1();
04678       Int_t pmtTruth2=hitInfo->GetPmtTruth2();
04679       Double_t earliestT1=hitInfo->GetEarliestT1();
04680       Int_t muon=13;
04681 
04682       if (plane>overallLastPlane) overallLastPlane=plane;
04683 
04684       Int_t sumTruth=pmtTruth1 | pmtTruth2;
04685       Bool_t genuine=(sumTruth & DigiSignal::kGenuine)==
04686         DigiSignal::kGenuine;
04687       Bool_t fibreLight=(sumTruth & DigiSignal::kFibreLight)==
04688         DigiSignal::kFibreLight;
04689       Bool_t darkNoise=(sumTruth & DigiSignal::kDarkNoise)==
04690         DigiSignal::kDarkNoise;
04691 
04692       if (!genuine && (fibreLight || darkNoise)) continue;
04693       
04694       if (plane>notNoiseLastPlane) notNoiseLastPlane=plane;
04695 
04696       if (!genuine) continue;
04697 
04698       //cut out the late decay electron, ND is alive for ~400 ns
04699       if (earliestT1>500e-9) continue;
04700       
04701       if (plane>particleLastPlane) particleLastPlane=plane;
04702 
04703       //in time but not necessarily a muon
04704       //if (plane>inTimeLastPlane) inTimeLastPlane=plane;
04705 
04706       //only look at muons
04707       if (abs(mainParticle)!=muon) continue;      
04708 
04709       if (plane>muonLastPlane) muonLastPlane=plane;
04710     }
04711 
04712     hEventLength->Fill(overallLastPlane+1);
04713     hEventLength2->Fill(notNoiseLastPlane+1);
04714     hEventLength3->Fill(particleLastPlane+1);
04715     //hEventLength3->Fill(inTimeLastPlane+1);
04716     hEventLength4->Fill(muonLastPlane+1);
04717 
04718   }//end of for
04719 
04720   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
04721   cGeom->SetFillColor(0);
04722   cGeom->Divide(2,3);
04723   cGeom->cd(1);
04724   hEventLength->Draw();
04725   cGeom->cd(2);
04726   hEventLength2->Draw();
04727   hEventLength2->SetLineColor(2);
04728   cGeom->cd(3);
04729   hEventLength3->Draw();
04730   hEventLength3->SetLineColor(3);
04731   cGeom->cd(4);
04732   hEventLength4->Draw();
04733   hEventLength->SetLineColor(4);
04734   cGeom->cd(5);
04735   hEventLength4->Draw();
04736   hEventLength2->Draw("sames");
04737   cGeom->cd(6);
04738   hEventLength4->Draw();
04739   hEventLength3->Draw("sames");
04740   hEventLength2->Draw("sames");
04741   hEventLength->Draw("sames");
04742 }
04743 
04744 //......................................................................
04745 
04746 void CDAnalysis::MuonResponse()
04747 {
04748   MSG("CDAnalysis",Msg::kInfo) 
04749     <<" ** Running MuonResponse method... **"<<endl;
04750 
04751   //open the output file for the histograms
04752   fOutFile=this->OpenFile(fRunNumber,"MuonRes");
04753 
04754   TH2F *hPeVsRange=new TH2F("hPeVsRange","PeVsRange",
04755                             20,40,60,50,0,10);
04756   hPeVsRange->GetXaxis()->SetTitle("Last Plane");
04757   hPeVsRange->GetXaxis()->CenterTitle();
04758   hPeVsRange->GetYaxis()->SetTitle("Greatest PE Value");
04759   hPeVsRange->GetYaxis()->CenterTitle();
04760   hPeVsRange->SetFillColor(0);
04761   //hPeVsRange->SetBit(TH1::kCanRebin);
04762 
04763   TH2F *hPeVsRangeGen=new TH2F("hPeVsRangeGen","PeVsRangeGen",
04764                             20,40,60,50,0,10);
04765   hPeVsRangeGen->GetXaxis()->SetTitle("Last Plane");
04766   hPeVsRangeGen->GetXaxis()->CenterTitle();
04767   hPeVsRangeGen->GetYaxis()->SetTitle("Greatest PE Value");
04768   hPeVsRangeGen->GetYaxis()->CenterTitle();
04769   hPeVsRangeGen->SetFillColor(0);
04770   //hPeVsRangeGen->SetBit(TH1::kCanRebin);
04771 
04772   TH2F *hPeVsRangeGen2=new TH2F("hPeVsRangeGen2","PeVsRangeGen2",
04773                             20,40,60,50,0,10);
04774   hPeVsRangeGen2->GetXaxis()->SetTitle("Last Plane");
04775   hPeVsRangeGen2->GetXaxis()->CenterTitle();
04776   hPeVsRangeGen2->GetYaxis()->SetTitle("Greatest PE Value");
04777   hPeVsRangeGen2->GetYaxis()->CenterTitle();
04778   hPeVsRangeGen2->SetFillColor(0);
04779   //hPeVsRangeGen2->SetBit(TH1::kCanRebin);
04780 
04781   TH2F *hPeVsRangeGen3=new TH2F("hPeVsRangeGen3","PeVsRangeGen3",
04782                             20,40,60,50,0,10);
04783   hPeVsRangeGen3->GetXaxis()->SetTitle("Last Plane");
04784   hPeVsRangeGen3->GetXaxis()->CenterTitle();
04785   hPeVsRangeGen3->GetYaxis()->SetTitle("Greatest PE Value");
04786   hPeVsRangeGen3->GetYaxis()->CenterTitle();
04787   hPeVsRangeGen3->SetFillColor(0);
04788   //hPeVsRangeGen3->SetBit(TH1::kCanRebin);
04789 
04790   TH2F *hPeVsRangeXTalk=new TH2F("hPeVsRangeXTalk","PeVsRangeXTalk",
04791                             20,40,60,50,0,10);
04792   hPeVsRangeXTalk->GetXaxis()->SetTitle("Last Plane");
04793   hPeVsRangeXTalk->GetXaxis()->CenterTitle();
04794   hPeVsRangeXTalk->GetYaxis()->SetTitle("Greatest PE Value");
04795   hPeVsRangeXTalk->GetYaxis()->CenterTitle();
04796   hPeVsRangeXTalk->SetFillColor(0);
04797   //hPeVsRangeXTalk->SetBit(TH1::kCanRebin);
04798 
04799   TH2F *hPeVsRangeXTalk2=new TH2F("hPeVsRangeXTalk2","PeVsRangeXTalk2",
04800                             20,40,60,50,0,10);
04801   hPeVsRangeXTalk2->GetXaxis()->SetTitle("Last Plane");
04802   hPeVsRangeXTalk2->GetXaxis()->CenterTitle();
04803   hPeVsRangeXTalk2->GetYaxis()->SetTitle("Greatest PE Value");
04804   hPeVsRangeXTalk2->GetYaxis()->CenterTitle();
04805   hPeVsRangeXTalk2->SetFillColor(0);
04806   //hPeVsRangeXTalk2->SetBit(TH1::kCanRebin);
04807 
04808   TH2F *hPeVsRangeXTalk3=new TH2F("hPeVsRangeXTalk3","PeVsRangeXTalk3",
04809                             20,40,60,50,0,10);
04810   hPeVsRangeXTalk3->GetXaxis()->SetTitle("Last Plane");
04811   hPeVsRangeXTalk3->GetXaxis()->CenterTitle();
04812   hPeVsRangeXTalk3->GetYaxis()->SetTitle("Greatest PE Value");
04813   hPeVsRangeXTalk3->GetYaxis()->CenterTitle();
04814   hPeVsRangeXTalk3->SetFillColor(0);
04815   //hPeVsRangeXTalk3->SetBit(TH1::kCanRebin);
04816 
04817   TH1F *hNumPlanes=new TH1F("hNumPlanes","NumPlanes hit",77,-2,75);
04818   hNumPlanes->GetXaxis()->SetTitle("Number of Planes Hit");
04819   hNumPlanes->GetXaxis()->CenterTitle();
04820   hNumPlanes->GetYaxis()->SetTitle("");
04821   hNumPlanes->GetYaxis()->CenterTitle();
04822   hNumPlanes->SetFillColor(0);
04823   hNumPlanes->SetBit(TH1::kCanRebin);
04824 
04825   TH1F *h15_18All=new TH1F("h15_18All","h15_18All",1000,-2,75);
04826   h15_18All->GetXaxis()->SetTitle("SigCors");
04827   h15_18All->GetXaxis()->CenterTitle();
04828   h15_18All->GetYaxis()->SetTitle("");
04829   h15_18All->GetYaxis()->CenterTitle();
04830   h15_18All->SetFillColor(0);
04831   h15_18All->SetBit(TH1::kCanRebin);
04832 
04833   TH1F *h15_18=new TH1F("h15_18","h15_18",1000,-2,75);
04834   h15_18->GetXaxis()->SetTitle("SigCors");
04835   h15_18->GetXaxis()->CenterTitle();
04836   h15_18->GetYaxis()->SetTitle("");
04837   h15_18->GetYaxis()->CenterTitle();
04838   h15_18->SetFillColor(0);
04839   h15_18->SetBit(TH1::kCanRebin);
04840 
04841   TH1F *hSigCorTotal=new TH1F("hSigCorTotal","hSigCorTotal",1000,-2,75);
04842   hSigCorTotal->GetXaxis()->SetTitle("SigCors");
04843   hSigCorTotal->GetXaxis()->CenterTitle();
04844   hSigCorTotal->GetYaxis()->SetTitle("");
04845   hSigCorTotal->GetYaxis()->CenterTitle();
04846   hSigCorTotal->SetFillColor(0);
04847   hSigCorTotal->SetBit(TH1::kCanRebin);
04848 
04849   TH1F *hSigCorTotalTight=new TH1F("hSigCorTotalTight",
04850                                    "hSigCorTotalTight",1000,-2,75);
04851   hSigCorTotalTight->GetXaxis()->SetTitle("SigCors");
04852   hSigCorTotalTight->GetXaxis()->CenterTitle();
04853   hSigCorTotalTight->GetYaxis()->SetTitle("");
04854   hSigCorTotalTight->GetYaxis()->CenterTitle();
04855   hSigCorTotalTight->SetFillColor(0);
04856   hSigCorTotalTight->SetBit(TH1::kCanRebin);
04857 
04858   TH1F *hSigCorTotalPeak=new TH1F("hSigCorTotalPeak",
04859                                   "hSigCorTotalPeak",1000,-2,75);
04860   hSigCorTotalPeak->GetXaxis()->SetTitle("SigCors");
04861   hSigCorTotalPeak->GetXaxis()->CenterTitle();
04862   hSigCorTotalPeak->GetYaxis()->SetTitle("");
04863   hSigCorTotalPeak->GetYaxis()->CenterTitle();
04864   hSigCorTotalPeak->SetFillColor(0);
04865   hSigCorTotalPeak->SetBit(TH1::kCanRebin);
04866 
04867   TH1F *hNumPlanesAll=new TH1F("hNumPlanesAll","NumPlanesAll hit",
04868                                77,-2,75);
04869   hNumPlanesAll->GetXaxis()->SetTitle("Number of Planes Hit");
04870   hNumPlanesAll->GetXaxis()->CenterTitle();
04871   hNumPlanesAll->GetYaxis()->SetTitle("");
04872   hNumPlanesAll->GetYaxis()->CenterTitle();
04873   hNumPlanesAll->SetFillColor(0);
04874   hNumPlanesAll->SetBit(TH1::kCanRebin);
04875 
04876   TH1F *hNumPlanesMu=new TH1F("hNumPlanesMu","hNumPlanesMu hit",
04877                               77,-2,75);
04878   hNumPlanesMu->GetXaxis()->SetTitle("Number of Planes Hit");
04879   hNumPlanesMu->GetXaxis()->CenterTitle();
04880   hNumPlanesMu->GetYaxis()->SetTitle("");
04881   hNumPlanesMu->GetYaxis()->CenterTitle();
04882   hNumPlanesMu->SetFillColor(0);
04883   hNumPlanesMu->SetLineColor(2);
04884   hNumPlanesMu->SetBit(TH1::kCanRebin);
04885   
04886   TH1F *hFirstPlane=new TH1F("hFirstPlane","FirstPlane hit",77,-2,75);
04887   hFirstPlane->GetXaxis()->SetTitle("First Plane Hit");
04888   hFirstPlane->GetXaxis()->CenterTitle();
04889   hFirstPlane->GetYaxis()->SetTitle("");
04890   hFirstPlane->GetYaxis()->CenterTitle();
04891   hFirstPlane->SetFillColor(0);
04892   hFirstPlane->SetBit(TH1::kCanRebin);
04893 
04894   TH1F *hEventLength=new TH1F("hEventLength","EventLength hit",
04895                               77,-2,75);
04896   hEventLength->GetXaxis()->SetTitle("Event Length (planes)");
04897   hEventLength->GetXaxis()->CenterTitle();
04898   hEventLength->GetYaxis()->SetTitle("");
04899   hEventLength->GetYaxis()->CenterTitle();
04900   hEventLength->SetFillColor(0);
04901   hEventLength->SetBit(TH1::kCanRebin);
04902 
04903   TH1F *hEventLength2=new TH1F("hEventLength2","EventLength",77,-2,75);
04904   hEventLength2->GetXaxis()->SetTitle("Event Length (planes)");
04905   hEventLength2->GetXaxis()->CenterTitle();
04906   hEventLength2->GetYaxis()->SetTitle("");
04907   hEventLength2->GetYaxis()->CenterTitle();
04908   hEventLength2->SetFillColor(0);
04909   hEventLength2->SetBit(TH1::kCanRebin);
04910 
04911   TH1F *hEventLength3=new TH1F("hEventLength3","EventLength",77,-2,75);
04912   hEventLength3->GetXaxis()->SetTitle("Event Length (planes)");
04913   hEventLength3->GetXaxis()->CenterTitle();
04914   hEventLength3->GetYaxis()->SetTitle("");
04915   hEventLength3->GetYaxis()->CenterTitle();
04916   hEventLength3->SetFillColor(0);
04917   hEventLength3->SetBit(TH1::kCanRebin);
04918 
04919   TH2F *hCkvAdcVsRange=new TH2F("hCkvAdcVsRange","CkvAdcVsRange",
04920                                 20,40,60,100,-1,1500);
04921   hCkvAdcVsRange->GetXaxis()->SetTitle("Last Plane");
04922   hCkvAdcVsRange->GetXaxis()->CenterTitle();
04923   hCkvAdcVsRange->GetYaxis()->SetTitle("Ckv ADC");
04924   hCkvAdcVsRange->GetYaxis()->CenterTitle();
04925   hCkvAdcVsRange->SetFillColor(0);
04926   hCkvAdcVsRange->SetBit(TH1::kCanRebin);
04927 
04928   //sum of all strip ends, normal and offset planes
04929   //tracked
04930   TProfile* pSigCorVsPlane=new TProfile("pSigCorVsPlane",
04931                                         "pSigCorVsPlane",
04932                                         62,0,62);
04933   TProfile* pSigCorVsOsPlane=new TProfile("pSigCorVsOsPlane",
04934                                           "pSigCorVsOsPlane",
04935                                           62,0,62);
04936 
04937   //xtalk + untracked hits
04938   TProfile* pSigCorVsPlaneX=new TProfile("pSigCorVsPlaneX",
04939                                          "pSigCorVsPlaneX",
04940                                          62,0,62);
04941   TProfile* pSigCorVsOsPlaneX=new TProfile("pSigCorVsOsPlaneX",
04942                                            "pSigCorVsOsPlaneX",
04943                                            62,0,62);
04944 
04945   //total
04946   TProfile* pSigCorVsPlaneT=new TProfile("pSigCorVsPlaneT",
04947                                          "pSigCorVsPlaneT",
04948                                          62,0,62);
04949   TProfile* pSigCorVsOsPlaneT=new TProfile("pSigCorVsOsPlaneT",
04950                                            "pSigCorVsOsPlaneT",
04951                                            62,0,62);
04952 
04953   //individual strip ends
04954   //tracked
04955   TProfile* pSigCorVsPlaneO1=new TProfile("pSigCorVsPlaneO1",
04956                                           "pSigCorVsPlaneO1",
04957                                           62,0,62);
04958   TProfile* pSigCorVsPlaneO2=new TProfile("pSigCorVsPlaneO2",
04959                                           "pSigCorVsPlaneO2",
04960                                           62,0,62);
04961   TProfile* pSigCorVsPlaneE1=new TProfile("pSigCorVsPlaneE1",
04962                                           "pSigCorVsPlaneE1",
04963                                           62,0,62);
04964   TProfile* pSigCorVsPlaneE2=new TProfile("pSigCorVsPlaneE2",
04965                                           "pSigCorVsPlaneE2",
04966                                           62,0,62);
04967   //xtalk + untracked hits
04968   TProfile* pSigCorVsPlaneO1X=new TProfile("pSigCorVsPlaneO1X",
04969                                           "pSigCorVsPlaneO1X",
04970                                           62,0,62);
04971   TProfile* pSigCorVsPlaneO2X=new TProfile("pSigCorVsPlaneO2X",
04972                                           "pSigCorVsPlaneO2X",
04973                                           62,0,62);
04974   TProfile* pSigCorVsPlaneE1X=new TProfile("pSigCorVsPlaneE1X",
04975                                           "pSigCorVsPlaneE1X",
04976                                           62,0,62);
04977   TProfile* pSigCorVsPlaneE2X=new TProfile("pSigCorVsPlaneE2X",
04978                                           "pSigCorVsPlaneE2X",
04979                                           62,0,62);
04980   //total
04981   TProfile* pSigCorVsPlaneO1T=new TProfile("pSigCorVsPlaneO1T",
04982                                           "pSigCorVsPlaneO1T",
04983                                           62,0,62);
04984   TProfile* pSigCorVsPlaneO2T=new TProfile("pSigCorVsPlaneO2T",
04985                                           "pSigCorVsPlaneO2T",
04986                                           62,0,62);
04987   TProfile* pSigCorVsPlaneE1T=new TProfile("pSigCorVsPlaneE1T",
04988                                           "pSigCorVsPlaneE1T",
04989                                           62,0,62);
04990   TProfile* pSigCorVsPlaneE2T=new TProfile("pSigCorVsPlaneE2T",
04991                                           "pSigCorVsPlaneE2T",
04992                                           62,0,62);
04993 
04994   //individual strip ends - offset planes
04995   //tracked
04996   TProfile* pSigCorVsOsPlaneO1=new TProfile("pSigCorVsOsPlaneO1",
04997                                             "pSigCorVsOsPlaneO1",
04998                                             62,0,62);
04999   TProfile* pSigCorVsOsPlaneO2=new TProfile("pSigCorVsOsPlaneO2",
05000                                             "pSigCorVsOsPlaneO2",
05001                                             62,0,62);
05002   TProfile* pSigCorVsOsPlaneE1=new TProfile("pSigCorVsOsPlaneE1",
05003                                             "pSigCorVsOsPlaneE1",
05004                                             62,0,62);
05005   TProfile* pSigCorVsOsPlaneE2=new TProfile("pSigCorVsOsPlaneE2",
05006                                             "pSigCorVsOsPlaneE2",
05007                                             62,0,62);
05008 
05009   //xtalk + untracked hits
05010   TProfile* pSigCorVsOsPlaneO1X=new TProfile("pSigCorVsOsPlaneO1X",
05011                                              "pSigCorVsOsPlaneO1X",
05012                                              62,0,62);
05013   TProfile* pSigCorVsOsPlaneO2X=new TProfile("pSigCorVsOsPlaneO2X",
05014                                             "pSigCorVsOsPlaneO2X",
05015                                             62,0,62);
05016   TProfile* pSigCorVsOsPlaneE1X=new TProfile("pSigCorVsOsPlaneE1X",
05017                                             "pSigCorVsOsPlaneE1X",
05018                                             62,0,62);
05019   TProfile* pSigCorVsOsPlaneE2X=new TProfile("pSigCorVsOsPlaneE2X",
05020                                             "pSigCorVsOsPlaneE2X",
05021                                             62,0,62);
05022   //total
05023   TProfile* pSigCorVsOsPlaneO1T=new TProfile("pSigCorVsOsPlaneO1T",
05024                                             "pSigCorVsOsPlaneO1T",
05025                                             62,0,62);
05026   TProfile* pSigCorVsOsPlaneO2T=new TProfile("pSigCorVsOsPlaneO2T",
05027                                             "pSigCorVsOsPlaneO2T",
05028                                             62,0,62);
05029   TProfile* pSigCorVsOsPlaneE1T=new TProfile("pSigCorVsOsPlaneE1T",
05030                                             "pSigCorVsOsPlaneE1T",
05031                                             62,0,62);
05032   TProfile* pSigCorVsOsPlaneE2T=new TProfile("pSigCorVsOsPlaneE2T",
05033                                             "pSigCorVsOsPlaneE2T",
05034                                             62,0,62);
05035 
05036   TProfile* pEnVsRange=new TProfile("pEnVsRange","pEnVsRange",
05037                                     62,0,62);
05038 
05039   vector<TProfile*> pSigCorVsDist;
05040   vector<TProfile*> pSigCorVsDistN;
05041   vector<Int_t> vWindowSize;
05042   vector<Float_t> bigAv;
05043   vector<Int_t> bigAvCounter;
05044   Float_t sum15_18=0;
05045   Float_t sum15_18Counter=0;
05046   Float_t sum15_18Mip=0;
05047   Float_t sum15_18MipCounter=0;
05048   Float_t sumSigCorTotal=0;
05049   Float_t sumSigCorTotalCounter=0;
05050   Float_t sumMipTotal=0;
05051   Float_t sumMipTotalCounter=0;
05052 
05053   Int_t lastPlaneOddCounter=0;
05054   Int_t lastPlaneEvenCounter=0;
05055   Int_t lastPlaneO1Counter=0;
05056   Int_t lastPlaneO2Counter=0;
05057   Int_t lastPlaneE1Counter=0;
05058   Int_t lastPlaneE2Counter=0;
05059   Int_t lastPlaneOBothCounter=0;
05060   Int_t lastPlaneEBothCounter=0;
05061 
05062   Int_t totalCounter=0;
05063   Int_t firstPlaneInPairCounter=0;
05064   Int_t sharedPmtCounter=0;
05065   Int_t sharedPmtXTalkCounter=0;
05066   Int_t side1Counter=0;
05067   Int_t side1XTalkCounter=0;
05068   Int_t side2Counter=0;
05069   Int_t side2XTalkCounter=0;
05070   Int_t doubleCounter=0;
05071   Int_t doubleXTalkCounter=0;
05072   Int_t notGenuineOrXTalkCounter=0;
05073 
05074   //num maps for all stripends
05075   map<Int_t,Float_t> num;
05076   map<Int_t,Float_t> numX;
05077   map<Int_t,Float_t> numT;
05078   map<Int_t,Float_t> numOs;
05079   map<Int_t,Float_t> numOsX;
05080   map<Int_t,Float_t> numOsT;
05081 
05082   //non-offset num maps for individual stripends
05083   map<Int_t,Float_t> numO1;
05084   map<Int_t,Float_t> numO1X;
05085   map<Int_t,Float_t> numO1T;
05086   map<Int_t,Float_t> numO2;
05087   map<Int_t,Float_t> numO2X;
05088   map<Int_t,Float_t> numO2T;
05089   map<Int_t,Float_t> numE1;
05090   map<Int_t,Float_t> numE1X;
05091   map<Int_t,Float_t> numE1T;
05092   map<Int_t,Float_t> numE2;
05093   map<Int_t,Float_t> numE2X;
05094   map<Int_t,Float_t> numE2T;
05095 
05096   //offset num maps for individual stripends
05097   map<Int_t,Float_t> numOsO1;
05098   map<Int_t,Float_t> numOsO1X;
05099   map<Int_t,Float_t> numOsO1T;
05100   map<Int_t,Float_t> numOsO2;
05101   map<Int_t,Float_t> numOsO2X;
05102   map<Int_t,Float_t> numOsO2T;
05103   map<Int_t,Float_t> numOsE1;
05104   map<Int_t,Float_t> numOsE1X;
05105   map<Int_t,Float_t> numOsE1T;
05106   map<Int_t,Float_t> numOsE2;
05107   map<Int_t,Float_t> numOsE2X;
05108   map<Int_t,Float_t> numOsE2T;
05109 
05110   Int_t noTrackCounter=0;
05111   Int_t passPidCounter=0;
05112  
05116   
05117   this->InitialiseLoopVariables();  
05118   
05119   for(Int_t event=0;event<fEvents;event++){
05120     
05121     this->SetLoopVariables(event);
05122 
05123     if (this->CutOnDeadChips()) continue;
05124     if (this->CutOnPid()) continue;
05125     //cut on not straight tracks
05126     //Double_t mainX1Cut=0.5;
05127     //if (!this->IsStraightTrack(mainX1Cut)){
05128     //continue;
05129     //}
05130 
05131     //count the number of events passing the pid
05132     passPidCounter++;
05133 
05134     map<Int_t,Int_t> numPlanesHit;
05135     map<Int_t,Int_t> numPlanesHit1;
05136     map<Int_t,Int_t> numPlanesHit2;
05137     map<Int_t,Int_t> numPlanesHitAll;
05138     map<Int_t,Float_t> planeSigCor;
05139     map<Int_t,Float_t> planeSigCorX;
05140     map<Int_t,Float_t> planeSigCorT;
05141     map<Int_t,Float_t> planeSigCorO1;    
05142     map<Int_t,Float_t> planeSigCorO1X;
05143     map<Int_t,Float_t> planeSigCorO1T;
05144     map<Int_t,Float_t> planeSigCorO2;
05145     map<Int_t,Float_t> planeSigCorO2X;
05146     map<Int_t,Float_t> planeSigCorO2T;
05147     map<Int_t,Float_t> planeSigCorE1;
05148     map<Int_t,Float_t> planeSigCorE1X;
05149     map<Int_t,Float_t> planeSigCorE1T;
05150     map<Int_t,Float_t> planeSigCorE2;
05151     map<Int_t,Float_t> planeSigCorE2X;
05152     map<Int_t,Float_t> planeSigCorE2T;
05153 
05154     map<Int_t,Float_t> planeMip;
05155     map<Int_t,Float_t> planeMipX;
05156     map<Int_t,Float_t> planeMipT;
05157 
05158     map<Int_t,Float_t> planePe;
05159     map<Int_t,Float_t> planeGreatestPe;
05160 
05161     Double_t sigCorTotal=0;
05162 
05163     //get tclones arrays for this snarl
05164     TClonesArray &cTrk=*fTrkHitInfo;
05165     Int_t numTrkHits=fTrkHitInfo->GetEntries();
05166     TClonesArray &cUnTrk = *fUnTrkHitInfo;
05167     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
05168     //CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
05169     TClonesArray &cXTalk = *fXTalkHits;
05170     Int_t numXTalkHits=fXTalkHits->GetEntries();
05171     //TClonesArray &cTruth = *fTruthHitInfo;
05172     Int_t numTruthHits=0;
05173     if (fTruthHitInfo) numTruthHits=fTruthHitInfo->GetEntries();
05174 
05175     //look for untracked big events
05176     if (numTrkHits<2 && numXTalkHits+numUnTrkHits>1){
05177       MSG("CDAnalysis",Msg::kDebug)
05178         <<"Event="<<event
05179         <<", Num hits: trk="<<numTrkHits<<", unTrk="<<numUnTrkHits
05180         <<", xtalk="<<numXTalkHits<<", truth="<<numTruthHits
05181         <<endl;
05182       noTrackCounter++;
05183       //continue;
05184     }
05185 
05187     //loop over the untracked hits in the snarl
05189     for (Int_t hit=0;hit<numUnTrkHits;hit++){
05190       //cast the tclonesarray up to a trackedhitinfo object
05191       CDTrackedHitInfo *hitInfo=
05192         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
05193 
05194       this->ReadInHitInfo(hitInfo);
05195 
05196       if (fPlane==0 && fChargeSigCor>1000){
05197         MSG("CDAnalysis",Msg::kDebug)
05198           <<"XTalk Event="<<event
05199           <<", fPlane="<<fPlane
05200           <<", fStrip="<<fStrip
05201           <<", fStripend="<<fStripend
05202           <<", fChargeAdc="<<fChargeAdc
05203           <<", fSigCor="<<fChargeSigCor<<endl;
05204       }
05205 
05206       //cut out the bad channels
05207       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
05208 
05209       //count the number of planes hit
05210       numPlanesHitAll[fPlane]++;
05211 
05212       //check the channel's sanity
05213       this->StandardSanityChecks();
05214 
05215       //add up the charge of the hits in each plane
05216       planeSigCorX[fPlane]+=fChargeSigCor;
05217       planeSigCorT[fPlane]+=fChargeSigCor;
05218       planeMipX[fPlane]+=fChargeMip;
05219       planeMipT[fPlane]+=fChargeMip;
05220       if (fO1) planeSigCorO1X[fPlane]+=fChargeSigCor;
05221       if (fO2) planeSigCorO2X[fPlane]+=fChargeSigCor;
05222       if (fE1) planeSigCorE1X[fPlane]+=fChargeSigCor;
05223       if (fE2) planeSigCorE2X[fPlane]+=fChargeSigCor;
05224       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
05225       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
05226       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
05227       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
05228 
05229       if (fChargePe>planeGreatestPe[fPlane]) planeGreatestPe[fPlane]=
05230                                                fChargePe;
05231 
05232       if (fPlane==0) continue;
05233       //sum the sigcor in the event
05234       //make up for no plane 0 with 2 times plane 1
05235       else if (fPlane==1) sigCorTotal+=2*fChargeSigCor;
05236       else sigCorTotal+=fChargeSigCor;
05237     }
05238 
05240     //loop over xtalk hits in the snarl
05242     for (Int_t hit=0;hit<numXTalkHits;hit++){
05243       CDXTalkHitInfo *hitInfo=
05244         dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
05245 
05246       this->ReadInHitInfo(hitInfo);
05247       
05248       //cut out the bad channels
05249       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
05250 
05251       //count the number of planes hit
05252       numPlanesHitAll[fPlane]++;
05253 
05254       //check the channel's sanity
05255       this->StandardSanityChecks();
05256 
05257       //add up the charge of the hits in each plane
05258       planeSigCorX[fPlane]+=fChargeSigCor;
05259       planeSigCorT[fPlane]+=fChargeSigCor;
05260       planeMipX[fPlane]+=fChargeMip;
05261       planeMipT[fPlane]+=fChargeMip;
05262       if (fO1) planeSigCorO1X[fPlane]+=fChargeSigCor;
05263       if (fO2) planeSigCorO2X[fPlane]+=fChargeSigCor;
05264       if (fE1) planeSigCorE1X[fPlane]+=fChargeSigCor;
05265       if (fE2) planeSigCorE2X[fPlane]+=fChargeSigCor;
05266       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
05267       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
05268       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
05269       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
05270 
05271       if (fChargePe>planeGreatestPe[fPlane]) planeGreatestPe[fPlane]=
05272                                                fChargePe;
05273 
05274       if (fPlane==0) continue;
05275       //sum the sigcor in the event
05276       //make up for no plane 0 with 2 times plane 1
05277       else if (fPlane==1) sigCorTotal+=2*fChargeSigCor;
05278       else sigCorTotal+=fChargeSigCor;
05279     }
05280 
05281     Bool_t lastPlaneO1Hit=false;
05282     Bool_t lastPlaneO2Hit=false;
05283     Bool_t lastPlaneE1Hit=false;
05284     Bool_t lastPlaneE2Hit=false;
05285     Int_t previousfLastPlane=-1;
05286 
05288     //loop over the tracked hits
05290     for (Int_t hit=0;hit<numTrkHits;hit++){
05291       CDTrackedHitInfo *trackedHitInfo=
05292         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
05293           
05294       this->ReadInHitInfo(trackedHitInfo);
05295 
05296       //cut out the bad channels
05297       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
05298 
05299       //check the channel's sanity
05300       this->StandardSanityChecks();
05301 
05302       //calculate the first and last planes
05303       this->CalcFirstLastPlane(fPlane);
05304 
05305       //count the number of planes hit
05306       numPlanesHit[fPlane]++;
05307       numPlanesHitAll[fPlane]++;
05308 
05309       if (fLastPlane==fPlane && fPlane%2==0){
05310 
05311         //check if a new last plane has been found
05312         if (fLastPlane!=previousfLastPlane){
05313           lastPlaneE1Hit=false;
05314           lastPlaneE2Hit=false;
05315         }
05316         previousfLastPlane=fLastPlane;
05317 
05318         //check which stripend to set to true
05319         if (fStripend==1) lastPlaneE1Hit=true;
05320         if (fStripend==2) lastPlaneE2Hit=true;
05321 
05322         //set the hits in the other plane to be false
05323         lastPlaneO1Hit=false;
05324         lastPlaneO2Hit=false;
05325         MSG("CDAnalysis",Msg::kVerbose)
05326           <<"ev="<<event
05327           <<", last="<<fLastPlane
05328           <<", pl="<<fPlane
05329           <<", se="<<fStripend
05330           <<", E1="<<lastPlaneE1Hit
05331           <<", E2="<<lastPlaneE2Hit
05332           <<", O1="<<lastPlaneO1Hit
05333           <<", O2="<<lastPlaneO2Hit<<endl;
05334       }
05335       else if (fLastPlane==fPlane && fPlane%2==1){
05336 
05337         //check if a new last plane has been found
05338         if (fLastPlane!=previousfLastPlane){
05339           lastPlaneO1Hit=false;
05340           lastPlaneO2Hit=false;
05341         }
05342         previousfLastPlane=fLastPlane;
05343 
05344         //check which stripend to set to true
05345         if (fStripend==1) lastPlaneO1Hit=true;
05346         if (fStripend==2) lastPlaneO2Hit=true;
05347 
05348         //set the hits in the other plane to be false
05349         lastPlaneE1Hit=false;
05350         lastPlaneE2Hit=false;
05351 
05352         MSG("CDAnalysis",Msg::kVerbose)
05353           <<"ev="<<event
05354           <<", last="<<fLastPlane
05355           <<", pl="<<fPlane
05356           <<", se="<<fStripend
05357           <<", E1="<<lastPlaneE1Hit
05358           <<", E2="<<lastPlaneE2Hit
05359           <<", O1="<<lastPlaneO1Hit
05360           <<", O2="<<lastPlaneO2Hit<<endl;
05361       }
05362 
05363       //add up the charge of the hits in each plane
05364       planeSigCor[fPlane]+=fChargeSigCor;
05365       planeSigCorT[fPlane]+=fChargeSigCor;
05366       planeMip[fPlane]+=fChargeMip;
05367       planeMipT[fPlane]+=fChargeMip;
05368       if (fChargePe>planeGreatestPe[fPlane]) planeGreatestPe[fPlane]=
05369                                                fChargePe;
05370       planePe[fPlane]+=fChargePe;
05371       if (fO1) planeSigCorO1[fPlane]+=fChargeSigCor;
05372       if (fO2) planeSigCorO2[fPlane]+=fChargeSigCor;
05373       if (fE1) planeSigCorE1[fPlane]+=fChargeSigCor;
05374       if (fE2) planeSigCorE2[fPlane]+=fChargeSigCor;
05375       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
05376       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
05377       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
05378       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
05379 
05380       if (fPlane==0) continue;
05381       //sum the sigcor in the event
05382       //make up for no plane 0 with 2 times plane 1
05383       else if (fPlane==1) sigCorTotal+=2*fChargeSigCor;
05384       else sigCorTotal+=fChargeSigCor;
05385     }
05387     //end of loop over the tracked hits
05389 
05390     //fill histos for all data
05391     hNumPlanes->Fill(numPlanesHit.size());
05392     hNumPlanesAll->Fill(numPlanesHitAll.size());
05393     hEventLength->Fill(fLastPlane+1);
05394 
05395     //make sure that the first plane makes sense and was actually set
05396     if (fFirstPlane<0 || fFirstPlane>59) continue;
05397 
05398     //calculate the event energy
05399     Double_t eventEn=(fScEnDepPerMEU/fSigCorPerMEU)*sigCorTotal*
05400       (1/fRatioScEnToBeamEn);
05401     //calc the last plane on the track with no xtalk
05402     Int_t lastPlaneNoXTalk=this->CalcLastPlaneOnTrkNoXTalk();
05403 
05404     //fill the prof
05405     pEnVsRange->Fill(lastPlaneNoXTalk+1,eventEn);
05406 
05407     if (fLastPlane%2==1) lastPlaneOddCounter++;
05408     if (fLastPlane%2==0) lastPlaneEvenCounter++;
05409 
05410     //work out which stripends in the last plane were hit
05411     if (lastPlaneE1Hit || lastPlaneE2Hit){
05412       if (lastPlaneE1Hit && !lastPlaneE2Hit) lastPlaneE1Counter++;
05413       else if (!lastPlaneE1Hit && lastPlaneE2Hit) lastPlaneE2Counter++;
05414       else lastPlaneEBothCounter++;
05415     }
05416     else if (lastPlaneO1Hit || lastPlaneO2Hit){
05417       if (lastPlaneO1Hit && !lastPlaneO2Hit) lastPlaneO1Counter++;
05418       else if (!lastPlaneO1Hit && lastPlaneO2Hit) lastPlaneO2Counter++;
05419       else lastPlaneOBothCounter++;
05420     }
05421     else{
05422       MSG("CDAnalysis",Msg::kInfo)
05423         <<"Nothing hit!"<<endl;
05424 
05425       MSG("CDAnalysis",Msg::kInfo)
05426         <<"ev="<<event
05427         <<", Num hits: trk="<<numTrkHits<<", unTrk="<<numUnTrkHits
05428         <<", xtalk="<<numXTalkHits
05429         <<", E1="<<lastPlaneE1Hit
05430         <<", E2="<<lastPlaneE2Hit
05431         <<", O1="<<lastPlaneO1Hit
05432         <<", O2="<<lastPlaneO2Hit<<endl;
05433     }
05434 
05435     MSG("CDAnalysis",Msg::kVerbose)<<"New event="<<event<<endl;
05436 
05437     totalCounter++;
05438     //look for the second of a pair of shared pmts
05439     if ((fLastPlane==26 || fLastPlane==27 ||
05440          fLastPlane==30 || fLastPlane==31 ||
05441          fLastPlane==34 || fLastPlane==35 ||
05442          fLastPlane==38 || fLastPlane==39 ||
05443          fLastPlane==42 || fLastPlane==43 ||
05444          fLastPlane==46 || fLastPlane==47 ||
05445          fLastPlane==50 || fLastPlane==51 ||
05446          fLastPlane==54 || fLastPlane==55 ||
05447          fLastPlane==58 || fLastPlane==59)){
05448       //fLastPlaneOdd
05449       //fLastPlaneEven
05450       
05451       if (this->IsDoubleEnded(fLastPlane)){
05452         doubleCounter++;
05453         if (this->IsPlaneXTalkOnly(fLastPlane)){
05454           doubleXTalkCounter++;
05455         }
05456       }
05457       else if (this->IsPlaneSideHit(fLastPlane,StripEnd::kEast)){
05458         side1Counter++;
05459 
05460         if (this->IsPlaneXTalkOnly(fLastPlane)){
05461           side1XTalkCounter++;
05462         }
05463 
05464         if (this->IsSharedPmtHit(fLastPlane)){
05465           sharedPmtCounter++;
05466           if (this->IsPlaneXTalkOnly(fLastPlane)){
05467             sharedPmtXTalkCounter++;
05468           }
05469         }
05470       }
05471       else if (this->IsPlaneSideHit(fLastPlane,StripEnd::kWest)){
05472         side2Counter++;
05473          
05474         if (this->IsPlaneXTalkOnly(fLastPlane)){
05475           side2XTalkCounter++;
05476         }
05477  
05478         if (this->IsSharedPmtHit(fLastPlane)){
05479           sharedPmtCounter++;
05480           if (this->IsPlaneXTalkOnly(fLastPlane)){
05481             sharedPmtXTalkCounter++;
05482           }
05483           MSG("CDAnalysis",Msg::kWarning)
05484             <<"This should not happen at CalDet!"<<endl;
05485         }
05486       }
05487       
05488       MSG("CDAnalysis",Msg::kVerbose)
05489         <<"Shared="<<sharedPmtCounter
05490         <<" ("<<sharedPmtXTalkCounter<<")"
05491         <<", 2end="<<doubleCounter
05492         <<" ("<<doubleXTalkCounter<<")"
05493         <<", end1="<<side1Counter
05494         <<" ("<<side1XTalkCounter<<")"
05495         <<", end2="<<side2Counter
05496         <<" ("<<side2XTalkCounter<<")"
05497         <<endl;
05498     }
05499     else{
05500       firstPlaneInPairCounter++;
05501     }
05502 
05503     if (!this->IsGenuineOrXTalk(fLastPlane)){
05504       notGenuineOrXTalkCounter++;
05505     }
05506 
05507     //make event length cuts
05508     if (this->CutOnEventLength()) continue;
05509     //make track quality cuts
05510     if (this->CutOnTrackQuality()) continue;
05511 
05512     MAXMSG("CDAnalysis",Msg::kInfo,10)
05513       <<"Event passing plane cuts="<<event<<endl;
05514 
05515     //fill the total sigcor histo
05516     hSigCorTotal->Fill(sigCorTotal);
05517 
05518     //fill event length plots for those passing cuts
05519     hFirstPlane->Fill(fFirstPlane);
05520     hEventLength2->Fill(fLastPlane+1);
05521     hEventLength3->Fill(lastPlaneNoXTalk+1);
05522 
05523     //look at a certain part of the spectrum
05524     if (lastPlaneNoXTalk+1>50 && lastPlaneNoXTalk+1<53){
05525       //fill the total sigcor histo
05526       hSigCorTotalTight->Fill(sigCorTotal);
05527     }
05528     
05529     if (lastPlaneNoXTalk+1==51){
05530       //fill the total sigcor histo
05531       hSigCorTotalPeak->Fill(sigCorTotal);
05532     }
05533 
05534     //look at pe versus range
05535     hPeVsRange->Fill(fLastPlane+1,planeGreatestPe[fLastPlane]);
05536     if (this->IsPlaneGenuine(fLastPlane)){
05537       hPeVsRangeGen->Fill(fLastPlane+1,planeGreatestPe[fLastPlane]);
05538     }
05539     else{
05540       hPeVsRangeXTalk->Fill(fLastPlane+1,planeGreatestPe[fLastPlane]);
05541 
05542       //now look at second from last plane
05543       if (this->IsPlaneGenuine(fLastPlane-1)){
05544         hPeVsRangeGen2->Fill(fLastPlane+1-1,
05545                                planeGreatestPe[fLastPlane-1]);
05546       }
05547       else{
05548         hPeVsRangeXTalk2->Fill(fLastPlane+1-1,
05549                                planeGreatestPe[fLastPlane-1]);
05550 
05551         //now look at third from last plane
05552         if (this->IsPlaneGenuine(fLastPlane-2)){
05553           hPeVsRangeGen3->Fill(fLastPlane+1-2,
05554                                planeGreatestPe[fLastPlane-2]);
05555         }
05556         else{
05557           hPeVsRangeXTalk3->Fill(fLastPlane+1-2,
05558                                  planeGreatestPe[fLastPlane-2]);
05559         }
05560       }
05561     }
05562 
05563     hCkvAdcVsRange->Fill(fLastPlane+1,fKovADC3);
05564 
05566     //section for response
05568 
05569     //const Int_t reNormPlane=70;
05570     //Int_t planeOffset=reNormPlane-fLastPlane;
05571     const Int_t os=fLastPlane;
05572 
05573     //do nasty hack for plane 40 - very nasty!!!!
05574     //if (fRunNumber==70709 || fRunNumber==70705){
05575     //planeSigCor[40]=planeSigCor[38];
05576       //don't do xtalk since if pl 38 has zero xtalk then you will make
05577       //the map bigger and will average a zero!!!!
05578       //planeSigCorX[40]=planeSigCorX[38];
05579       //planeSigCorT[40]=planeSigCorT[38];
05580     //}
05581     //do nasty hack for plane 35 - very nasty!!!!
05582     if (fRunNumber>40000 && fRunNumber<60000){
05583       planeSigCor[35]=planeSigCor[37];
05584       planeSigCorT[35]=planeSigCorT[37];
05585     }
05586     //do nasty hack for plane 35 - very nasty!!!!
05587     else if (fRunNumber>100000 && fRunNumber<110000){
05588       //map<Int_t,Float_t> tmp=planeSigCor;
05589       //map<Int_t,Float_t> tmpT=planeSigCor;
05590       //if (tmp[15]!=0){
05591         //planeSigCor[13]=planeSigCor[15];
05592       //}
05593 
05594       //if (tmpT[15]!=0){
05595         //planeSigCorT[13]=planeSigCorT[15];
05596       //}
05597     }
05598 
05599     //fill profs for all stripends
05600     this->FillProfHisto(pSigCorVsPlane,num,planeSigCor);
05601     this->FillProfHisto(pSigCorVsPlaneX,numX,planeSigCorX);
05602     this->FillProfHisto(pSigCorVsPlaneT,numT,planeSigCorT);
05603     //offset
05604     this->FillProfHisto(pSigCorVsOsPlane,numOs,planeSigCor,os);
05605     this->FillProfHisto(pSigCorVsOsPlaneX,numOsX,planeSigCorX,os);
05606     this->FillProfHisto(pSigCorVsOsPlaneT,numOsT,planeSigCorT,os);
05607 
05608     //fill non-offset profs for individual stripends
05609     this->FillProfHisto(pSigCorVsPlaneO1,numO1,planeSigCorO1);
05610     this->FillProfHisto(pSigCorVsPlaneO1X,numO1X,planeSigCorO1X);
05611     this->FillProfHisto(pSigCorVsPlaneO1T,numO1T,planeSigCorO1T);
05612     this->FillProfHisto(pSigCorVsPlaneO2,numO2,planeSigCorO2);
05613     this->FillProfHisto(pSigCorVsPlaneO2X,numO2X,planeSigCorO2X);
05614     this->FillProfHisto(pSigCorVsPlaneO2T,numO2T,planeSigCorO2T);
05615     this->FillProfHisto(pSigCorVsPlaneE1,numE1,planeSigCorE1);
05616     this->FillProfHisto(pSigCorVsPlaneE1X,numE1X,planeSigCorE1X);
05617     this->FillProfHisto(pSigCorVsPlaneE1T,numE1T,planeSigCorE1T);
05618     this->FillProfHisto(pSigCorVsPlaneE2,numE2,planeSigCorE2);
05619     this->FillProfHisto(pSigCorVsPlaneE2X,numE2X,planeSigCorE2X);
05620     this->FillProfHisto(pSigCorVsPlaneE2T,numE2T,planeSigCorE2T);
05621 
05622     //fill offset profs for individual stripends
05623     this->FillProfHisto(pSigCorVsOsPlaneO1,numOsO1,planeSigCorO1,os);
05624     this->FillProfHisto(pSigCorVsOsPlaneO1X,numOsO1X,planeSigCorO1X,os);
05625     this->FillProfHisto(pSigCorVsOsPlaneO1T,numOsO1T,planeSigCorO1T,os);
05626     this->FillProfHisto(pSigCorVsOsPlaneO2,numOsO2,planeSigCorO2,os);
05627     this->FillProfHisto(pSigCorVsOsPlaneO2X,numOsO2X,planeSigCorO2X,os);
05628     this->FillProfHisto(pSigCorVsOsPlaneO2T,numOsO2T,planeSigCorO2T,os);
05629     this->FillProfHisto(pSigCorVsOsPlaneE1,numOsE1,planeSigCorE1,os);
05630     this->FillProfHisto(pSigCorVsOsPlaneE1X,numOsE1X,planeSigCorE1X,os);
05631     this->FillProfHisto(pSigCorVsOsPlaneE1T,numOsE1T,planeSigCorE1T,os);
05632     this->FillProfHisto(pSigCorVsOsPlaneE2,numOsE2,planeSigCorE2,os);
05633     this->FillProfHisto(pSigCorVsOsPlaneE2X,numOsE2X,planeSigCorE2X,os);
05634     this->FillProfHisto(pSigCorVsOsPlaneE2T,numOsE2T,planeSigCorE2T,os);
05635 
05637     //section for total event sigcor and mips
05639     Float_t localSumSigCorTotal=0;
05640     Float_t localSumSigCorTotalCounter=0;
05641     for (map<Int_t,Float_t>::iterator sig=planeSigCorT.begin();
05642          sig!=planeSigCorT.end();++sig){
05643       localSumSigCorTotal+=sig->second;
05644       localSumSigCorTotalCounter++;
05645     }
05646 
05647     //add total of this event to the sum of all events 
05648     if (localSumSigCorTotalCounter!=0){
05649       sumSigCorTotal+=localSumSigCorTotal;
05650       sumSigCorTotalCounter++;
05651     }
05652 
05653     Float_t localSumMipTotal=0;
05654     Float_t localSumMipTotalCounter=0;
05655     for (map<Int_t,Float_t>::iterator sig=planeMipT.begin();
05656          sig!=planeMipT.end();++sig){
05657       localSumMipTotal+=sig->second;
05658       localSumMipTotalCounter++;
05659     }
05660 
05661     //add total of this event to the sum of all events 
05662     if (localSumMipTotalCounter!=0){
05663       sumMipTotal+=localSumMipTotal;
05664       sumMipTotalCounter++;
05665     }
05666 
05668     //section for sliding window
05670     Int_t minEventLength=35;
05671     if (fLastPlane<minEventLength) continue;
05672 
05673     //initialise the profile histos
05674     static Bool_t firstTime=true;
05675     if (firstTime){
05676       for (Int_t p=15;p>1;p--){
05677         vWindowSize.push_back(p);
05678         bigAv.push_back(0);
05679         bigAvCounter.push_back(0);
05680       }
05681 
05682       for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
05683            windowSize!=vWindowSize.end();++windowSize){
05684         
05685         string sName=Form("%d",*windowSize);
05686         pSigCorVsDist.push_back
05687           (new TProfile(("pSigCorVsDist"+sName).c_str(),
05688                         ("pSigCorVsDist"+sName).c_str(),100,-2,40));
05689       }
05690     }
05691     firstTime=false;
05692 
05693     vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
05694     vector<Float_t>::iterator av=bigAv.begin();
05695     vector<Int_t>::iterator count=bigAvCounter.begin();
05696     Float_t localSum15_18=0;
05697     Float_t localSum15_18Counter=0;
05698     Float_t localSum15_18Mip=0;
05699     Float_t localSum15_18MipCounter=0;
05700 
05701     //loop over the different window sizes
05702     for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
05703          windowSize!=vWindowSize.end();++windowSize){
05704       
05705       //slide the window along from the end to 40-windowSize
05706       for (Int_t p=0;p<minEventLength-*windowSize;p++){
05707         Int_t windowStart=fLastPlane-p;
05708 
05709         MSG("CDAnalysis",Msg::kVerbose)
05710           <<"Window size="<<*windowSize
05711           <<", window start="<<windowStart
05712           <<endl;
05713 
05714         //loop through the hits in the window
05715         for (Int_t i=0;i<*windowSize;i++){
05716           Int_t plane=windowStart-i;
05717           
05718           //cut out planes that are greater than the last plane
05719           //in the view - ie the zeros at the end
05720           Bool_t doZeroCorrection=false;
05721           if (doZeroCorrection && 
05722               ((plane%2==0 && plane>fLastPlaneEven) || 
05723                (plane%2!=0 && plane>fLastPlaneOdd))){
05724             MSG("CDAnalysis",Msg::kVerbose)
05725               <<"Not using: Event="<<event
05726               <<", pl="<<plane
05727               <<", sigCor="<<planeSigCorT[plane]
05728               <<", fLastPlane="<<fLastPlane
05729               <<", fLastPlSig="<<planeSigCorT[fLastPlane]
05730               <<", fLastPlOdd="<<fLastPlaneOdd
05731               <<", fLastPlEven="<<fLastPlaneEven
05732               <<endl;
05733           }
05734           else{
05735 
05736             //calculate the best window value
05737             //if fLP=48 then the first plane included is 30
05738             //this is actually the 19th from the end of the track
05739             if (*windowSize==15 && windowStart==fLastPlane-18){
05740               localSum15_18+=planeSigCorT[plane];//total including xtalk
05741               localSum15_18Counter++;
05742               localSum15_18Mip+=planeMipT[plane];//total including xtalk
05743               localSum15_18MipCounter++;
05744 
05745               if (plane%2==0){//even
05746                 
05747               }
05748               else if (plane%2==1){//odd
05749 
05750               }
05751 
05752             }
05753 
05754             (*prof)->Fill(p,planeSigCorT[plane]);
05755             (*av)+=planeSigCorT[plane];
05756             (*count)++;
05757           }
05758         }
05759       }
05760       av++;
05761       count++;
05762       prof++;
05763     }
05764 
05765     if (localSum15_18Counter!=0){
05766       h15_18All->Fill(localSum15_18);
05767       h15_18->Fill(localSum15_18/15);
05768       sum15_18+=localSum15_18;//add this event's energy on to total
05769       sum15_18Counter++;
05770       sum15_18Mip+=localSum15_18Mip;
05771       sum15_18MipCounter++;
05772     }
05773 
05774     if (localSum15_18Counter==0 || localSum15_18<200){
05775       MAXMSG("CDAnalysis",Msg::kInfo,40)
05776         <<"Event="<<event<<", strange 15_18="<<localSum15_18
05777         <<", counter="<<localSum15_18Counter<<endl;
05778     }
05779 
05780   }//end of for                                       
05781   
05785 
05786   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05787 
05788   //turn off the stats box printing
05789   gStyle->SetOptStat(0);
05790 
05791   //all stripends
05792   string sTitle="Energy Deposition (SigCor, all Stripends)";
05793   string sXTitle="Distance from end of track (planes)";
05794   this->DrawResponsePlot(sTitle,pSigCorVsPlane,pSigCorVsPlaneX,
05795                          pSigCorVsPlaneT,num,numX,numT);
05796   sTitle="Energy Deposition Vs Distance (SigCor, all Stripends)";
05797   this->DrawResponsePlot(sTitle,pSigCorVsOsPlane,pSigCorVsOsPlaneX,
05798                          pSigCorVsOsPlaneT,numOs,numOsX,numOsT,sXTitle);
05799 
05800   //non-offset planes
05801   sTitle="Energy Deposition (SigCor in Odd Planes FD stripend)";
05802   this->DrawResponsePlot(sTitle,pSigCorVsPlaneO1,pSigCorVsPlaneO1X,
05803                          pSigCorVsPlaneO1T,numO1,numO1X,numO1T);
05804 
05805   sTitle="Energy Deposition (SigCor in Odd Planes ND stripend)";
05806   this->DrawResponsePlot(sTitle,pSigCorVsPlaneO2,pSigCorVsPlaneO2X,
05807                          pSigCorVsPlaneO2T,numO2,numO2X,numO2T);
05808 
05809   sTitle="Energy Deposition (SigCor in Even Planes FD stripend)";
05810   this->DrawResponsePlot(sTitle,pSigCorVsPlaneE1,pSigCorVsPlaneE1X,
05811                          pSigCorVsPlaneE1T,numE1,numE1X,numE1T);
05812 
05813   sTitle="Energy Deposition (SigCor in Even Planes ND stripend)";
05814   this->DrawResponsePlot(sTitle,pSigCorVsPlaneE2,pSigCorVsPlaneE2X,
05815                          pSigCorVsPlaneE2T,numE2,numE2X,numE2T);
05816 
05817   //offset planes
05818   sTitle="Energy Deposition Vs Distance (SigCor in Odd Planes FD stripend)";
05819   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneO1,pSigCorVsOsPlaneO1X,
05820                          pSigCorVsOsPlaneO1T,numOsO1,numOsO1X,numOsO1T,
05821                          sXTitle);
05822 
05823   sTitle="Energy Deposition Vs Distance (SigCor in Odd Planes ND stripend)";
05824   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneO2,pSigCorVsOsPlaneO2X,
05825                          pSigCorVsOsPlaneO2T,numOsO2,numOsO2X,numOsO2T,
05826                          sXTitle);
05827 
05828   sTitle="Energy Deposition Vs Distance (SigCor in Even Planes FD stripend)";
05829   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneE1,pSigCorVsOsPlaneE1X,
05830                          pSigCorVsOsPlaneE1T,numOsE1,numOsE1X,numOsE1T,
05831                          sXTitle);
05832 
05833   sTitle="Energy Deposition Vs Distance (SigCor in Even Planes ND stripend)";
05834   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneE2,pSigCorVsOsPlaneE2X,
05835                          pSigCorVsOsPlaneE2T,numOsE2,numOsE2X,numOsE2T,
05836                          sXTitle);
05837 
05838 
05839   //turn on the stats box printing
05840   gStyle->SetOptStat(11);
05841 
05842   TCanvas *cProf=new TCanvas("cProf","Prof",0,0,1200,800);
05843   cProf->SetFillColor(0);
05844   string sName="SlidingWindow.ps";
05845   cProf->Print((sName+"[").c_str());
05846   gErrorIgnoreLevel=1;
05847   //plot the unnormalised prof first
05848   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
05849        prof!=pSigCorVsDist.end();++prof){      
05850     cProf->Clear();
05851     (*prof)->Draw();
05852     (*prof)->SetTitle("Average SigCor in Sliding Window");
05853     (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
05854     (*prof)->GetYaxis()->SetTitle("Average SigCor");
05855     (*prof)->GetXaxis()->CenterTitle();
05856     (*prof)->GetYaxis()->CenterTitle();
05857     cProf->Print(sName.c_str());
05858   }
05859 
05860   //now normalise the prof
05861   vector<Float_t>::iterator av=bigAv.begin();
05862   vector<Int_t>::iterator count=bigAvCounter.begin();
05863   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
05864        prof!=pSigCorVsDist.end();++prof){
05865       
05866     //normalise the prof and scale the axes
05867     MSG("CDAnalysis",Msg::kDebug)
05868       <<"bigCounter="<<*count<<", bigAv="<<*av<<endl;
05869 
05870     //pSigCorVsDistN.push_back
05871     //(new TProfile(("pSigCorVsDistN"+sName).c_str(),
05872     //      ("pSigCorVsDistN"+sName).c_str(),100,-2,40));
05873     if (*av>0) (*prof)->Scale((*count)/(*av));
05874     (*prof)->SetMaximum(1.2);
05875     (*prof)->SetMinimum(0.8);
05876       
05877     cProf->Clear();
05878     (*prof)->Draw();
05879     (*prof)->SetTitle("Average SigCor in Sliding Window");
05880     (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
05881     (*prof)->GetYaxis()->SetTitle("Average SigCor");
05882     (*prof)->GetXaxis()->CenterTitle();
05883     (*prof)->GetYaxis()->CenterTitle();
05884     cProf->Print(sName.c_str());
05885     av++;
05886     count++;
05887   }
05888   //close the file
05889   gErrorIgnoreLevel=0;
05890   cProf->Print((sName+"]").c_str());
05891 
05892   //now do a few profs on the same plot
05893   TCanvas *cProf2=new TCanvas("cProf2","Prof",0,0,1200,800);
05894   cProf2->SetFillColor(0);
05895   sName="SlidingWindowAll.ps";
05896   //cProf2->Print((sName+"[").c_str());
05897   Int_t counter=0;
05898   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
05899        prof!=pSigCorVsDist.end();++prof){
05900 
05901     (*prof)->SetMaximum(1.09);
05902     (*prof)->SetMinimum(0.96);
05903 
05904     //count which prof got to
05905     counter++;
05906 
05907     //decide which profs to draw
05908     static Bool_t firstTime=true;
05909     if (counter==1 || counter==6 || counter==11){ 
05910       if (firstTime) {
05911         (*prof)->Draw();
05912         firstTime=false;
05913       }
05914       else  (*prof)->Draw("sames");
05915 
05916       (*prof)->SetTitle("Average SigCor in Sliding Window");
05917       (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
05918       (*prof)->GetYaxis()->SetTitle("Average SigCor");
05919       (*prof)->GetXaxis()->CenterTitle();
05920       (*prof)->GetYaxis()->CenterTitle();
05921       static Int_t color=2;
05922       (*prof)->SetLineColor(color);
05923       color+=2;
05924     }
05925   }
05926 
05927   //turn off the stats box printing
05928   //gStyle->SetOptStat(0);
05929   gStyle->SetOptStat(1111111);
05930 
05931   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
05932   cGeom->SetFillColor(0);
05933   cGeom->Divide(2,3);
05934   cGeom->cd(1);
05935   hEventLength2->Draw();
05936   cGeom->cd(2);
05937   hEventLength3->Draw();
05938   cGeom->cd(3);
05939   hFirstPlane->Draw();
05940   cGeom->cd(4);
05941   hEventLength->Draw();
05942   cGeom->cd(5);
05943   hNumPlanes->Draw();
05944   cGeom->cd(6);
05945   hNumPlanesAll->Draw();
05946   hNumPlanesMu->Draw("same");
05947  
05948   /*
05949   TCanvas *cCkv=new TCanvas("cCkv","Ckv",0,0,1200,800);
05950   cCkv->SetFillColor(0);
05951   cCkv->Divide(2,2);
05952   cCkv->cd(1);
05953   hCkvAdcVsRange->Draw("colz");
05954   hCkvAdcVsRange->Draw("profsame");
05955   cCkv->cd(2);
05956   TProfile* p=hCkvAdcVsRange->ProfileX();
05957   p->Draw();
05958   cCkv->cd(3);
05959   hCkvAdcVsRange->Draw("colz");
05960   p->Draw("sames");
05961   */
05962 
05963   TCanvas *c15_18=new TCanvas("c15_18","15_18",0,0,1200,800);
05964   c15_18->SetFillColor(0);
05965   c15_18->Divide(2,3);
05966   c15_18->cd(1);
05967   h15_18->Draw();
05968   c15_18->cd(2);
05969   h15_18All->Draw();
05970   c15_18->cd(3);
05971   hSigCorTotal->Draw();
05972   c15_18->cd(4);
05973   hSigCorTotalTight->Draw();
05974   c15_18->cd(5);
05975   hSigCorTotalPeak->Draw();
05976   c15_18->cd(6);
05977   pEnVsRange->Draw();
05978 
05979   MSG("CDAnalysis",Msg::kInfo) 
05980     <<endl
05981     <<"Mean sigCorTotal="<<hSigCorTotal->GetMean()<<endl
05982     <<"Ratio ScEn to BeamEn="<<fRatioScEnToBeamEn
05983     <<" ("<<1/fRatioScEnToBeamEn<<")"<<endl
05984     <<"GeV per SigCor="<<fScEnDepPerMEU/fSigCorPerMEU<<endl
05985     <<"Beam energy from Calorimetry (lose)="
05986     <<((fScEnDepPerMEU/fSigCorPerMEU)*
05987     hSigCorTotal->GetMean()*(1/fRatioScEnToBeamEn))/
05988     Munits::gigaelectronvolt<<" "<<Munits::base_energy_name<<endl
05989     <<"Beam energy from Calorimetry (tight)="
05990     <<((fScEnDepPerMEU/fSigCorPerMEU)*
05991     hSigCorTotalTight->GetMean()*(1/fRatioScEnToBeamEn))/
05992     Munits::gigaelectronvolt<<" "<<Munits::base_energy_name<<endl
05993     <<"Beam energy from Calorimetry (peak)="
05994     <<((fScEnDepPerMEU/fSigCorPerMEU)*
05995     hSigCorTotalPeak->GetMean()*(1/fRatioScEnToBeamEn))/
05996     Munits::gigaelectronvolt<<" "<<Munits::base_energy_name<<endl<<endl;
05997 
05998   /*
05999   TCanvas *cXtalk=new TCanvas("cXtalk","Xtalk",0,0,1200,800);
06000   cXtalk->SetFillColor(0);
06001   cXtalk->Divide(3,3);
06002   cXtalk->cd(1);
06003   hPeVsRange->Draw("colz");
06004   cXtalk->cd(2);
06005   hPeVsRangeGen->Draw("colz");
06006   cXtalk->cd(3);
06007   hPeVsRangeXTalk->Draw("colz");
06008 
06009   cXtalk->cd(5);
06010   hPeVsRangeGen2->Draw("colz");
06011   cXtalk->cd(6);
06012   hPeVsRangeXTalk2->Draw("colz");
06013   cXtalk->cd(8);
06014   hPeVsRangeGen3->Draw("colz");
06015   cXtalk->cd(9);
06016   hPeVsRangeXTalk3->Draw("colz");
06017   */
06018 
06019   Int_t oddEvenSum=lastPlaneEvenCounter+lastPlaneOddCounter;
06020   Float_t oddPercent=-1;
06021   Float_t evenPercent=-1;
06022   if (oddEvenSum) oddPercent=100.*lastPlaneOddCounter/oddEvenSum;
06023   if (oddEvenSum) evenPercent=100.*lastPlaneEvenCounter/oddEvenSum;
06024 
06025   MSG("CDAnalysis",Msg::kInfo) 
06026     <<"Last plane, odd="<<lastPlaneOddCounter<<" ("<<oddPercent<<"%)"
06027     <<", even="<<lastPlaneEvenCounter<<" ("<<evenPercent<<"%)"<<endl;
06028 
06029   Int_t totalSum=lastPlaneE1Counter+lastPlaneE2Counter+
06030     lastPlaneO1Counter+lastPlaneO2Counter+
06031     lastPlaneEBothCounter+lastPlaneOBothCounter;
06032   Float_t e1Percent=-1;
06033   Float_t e2Percent=-1;
06034   Float_t o1Percent=-1;
06035   Float_t o2Percent=-1;
06036   Float_t eBothPercent=-1;
06037   Float_t oBothPercent=-1;
06038   if (totalSum) o1Percent=100.*lastPlaneO1Counter/totalSum;
06039   if (totalSum) o2Percent=100.*lastPlaneO2Counter/totalSum;
06040   if (totalSum) e1Percent=100.*lastPlaneE1Counter/totalSum;
06041   if (totalSum) e2Percent=100.*lastPlaneE2Counter/totalSum;
06042   if (totalSum) eBothPercent=100.*lastPlaneEBothCounter/totalSum;
06043   if (totalSum) oBothPercent=100.*lastPlaneOBothCounter/totalSum;
06044 
06045   Float_t totalPercent=o1Percent+o2Percent+e1Percent+e2Percent+
06046     oBothPercent+eBothPercent;
06047 
06048   MSG("CDAnalysis",Msg::kInfo) 
06049     <<"Last Plane:"<<endl
06050     <<"  Total number hits="<<totalSum<<endl
06051     <<"  Hits on both sides of plane:"<<endl
06052     <<"    Odd="<<lastPlaneOBothCounter<<" ("<<oBothPercent<<"%)"<<endl
06053     <<"    Even="<<lastPlaneEBothCounter<<" ("<<eBothPercent<<"%)"<<endl
06054     <<"  Hits on only one side of plane:"<<endl
06055     <<"    Odd-ND="<<lastPlaneO2Counter<<" ("<<o2Percent<<"%)"<<endl
06056     <<"    Odd-FD="<<lastPlaneO1Counter<<" ("<<o1Percent<<"%)"<<endl
06057     <<"    Even-ND="<<lastPlaneE2Counter<<" ("<<e2Percent<<"%)"<<endl
06058     <<"    Even-FD="<<lastPlaneE1Counter<<" ("<<e1Percent<<"%)"<<endl
06059     <<"  Sum of 6 percentages="<<totalPercent<<endl;
06060 
06061   Float_t sharedXTalkPercent=-1;
06062   Float_t side1XTalkPercent=-1;
06063   Float_t side2XTalkPercent=-1;
06064   Float_t doubleXTalkPercent=-1;
06065   Float_t notGenuineOrXTalkPercent=-1;
06066   if (sharedPmtCounter) sharedXTalkPercent=100.*sharedPmtXTalkCounter/
06067                           sharedPmtCounter;
06068   if (side1Counter) side1XTalkPercent=100.*side1XTalkCounter/
06069                       side1Counter;
06070   if (side2Counter) side2XTalkPercent=100.*side2XTalkCounter/
06071                       side2Counter;
06072   if (doubleCounter) doubleXTalkPercent=100.*doubleXTalkCounter/
06073                       doubleCounter;
06074   if (totalCounter) notGenuineOrXTalkPercent=100.*
06075                       notGenuineOrXTalkCounter/totalCounter;
06076 
06077   MSG("CDAnalysis",Msg::kInfo) 
06078     <<endl
06079     <<"totalCounter="<<totalCounter<<endl
06080     <<"firstPlaneInPairCounter="<<firstPlaneInPairCounter<<endl
06081     <<"double="<<doubleCounter
06082     <<", xtalk="<<doubleXTalkCounter
06083     <<" ("<<doubleXTalkPercent<<"%)"<<endl
06084     <<"side1="<<side1Counter
06085     <<", xtalk="<<side1XTalkCounter
06086     <<" ("<<side1XTalkPercent<<"%)"<<endl
06087     <<"side2="<<side2Counter
06088     <<", xtalk="<<side2XTalkCounter
06089     <<" ("<<side2XTalkPercent<<"%)"<<endl
06090     <<"Number of times shared pmt on second of"
06091     <<" two planes was last plane="
06092     <<sharedPmtCounter<<endl
06093     <<"Number of times above was XTalk only="<<sharedPmtXTalkCounter
06094     <<" ("<<sharedXTalkPercent<<"%)"<<endl
06095     <<"notGenuineOrXTalkCounter="<<notGenuineOrXTalkCounter
06096     <<" ("<<notGenuineOrXTalkPercent<<"%)"<<endl;
06097 
06098   MSG("CDAnalysis",Msg::kInfo) 
06099     <<endl<<"passPidCounter="<<passPidCounter<<endl
06100     <<"noTrackCounter="<<noTrackCounter
06101     <<" ("<<Pct(noTrackCounter,passPidCounter)<<"%)"<<endl;
06102    
06103   if (sum15_18Counter!=0){
06104     MSG("CDAnalysis",Msg::kInfo) 
06105       <<endl
06106       <<" ** Calibration Summary **"<<endl
06107       <<"SigCor in sliding window 15_18:"<<endl
06108       <<"    SigCor dep="<<sum15_18<<" (N="<<sum15_18Counter<<")"<<endl
06109       <<"    Av SigCor dep="<<sum15_18/sum15_18Counter
06110       <<" +/- "<<100*(h15_18->GetRMS()/sqrt(h15_18->GetEntries()))/
06111       h15_18->GetMean()<<"%"<<endl
06112       <<"    Av SigCor dep per plane="<<(sum15_18/sum15_18Counter)/15
06113       <<" +/- "<<100*(h15_18->GetRMS()/sqrt(h15_18->GetEntries()))/
06114       h15_18->GetMean()<<"%"<<endl
06115       <<"MIPs in sliding window 15_18:"<<endl
06116       <<"    MIPs dep="<<sum15_18Mip
06117       <<" (N="<<sum15_18MipCounter<<")"<<endl
06118       <<"    Av MIPs dep="<<sum15_18Mip/sum15_18MipCounter
06119       <<endl;
06120     if (sumSigCorTotalCounter!=0){
06121       MSG("CDAnalysis",Msg::kInfo) 
06122         <<"SigCor of whole event:"<<endl
06123         <<"    Sum of SigCor dep="<<sumSigCorTotal
06124         <<" (N="<<sumSigCorTotalCounter<<")"<<endl
06125         <<"    Av sigCor dep="
06126         <<sumSigCorTotal/sumSigCorTotalCounter<<endl
06127         <<"    1 sigCor="
06128         <<1800/(sumSigCorTotal/sumSigCorTotalCounter)<<" MeV"
06129         <<endl;
06130     }
06131     if (sumMipTotalCounter!=0){
06132       MSG("CDAnalysis",Msg::kInfo) 
06133         <<"MIPs of whole event:"<<endl
06134         <<"    Sum of MIPs dep="<<sumMipTotal
06135         <<" (N="<<sumMipTotalCounter<<")"<<endl
06136         <<"    Av MIPs dep="
06137         <<sumMipTotal/sumMipTotalCounter<<endl
06138         <<"    1 MIP="
06139         <<1800/(sumMipTotal/sumMipTotalCounter)<<" MeV"<<endl
06140         <<"    1 GeV="
06141         <<(sumMipTotal/sumMipTotalCounter)/1.8<<" MIPs"
06142         <<endl<<endl;
06143     }
06144   }
06145 
06146   MSG("CDAnalysis",Msg::kInfo) 
06147     <<" ** Finished MuonResponse method **"<<endl;
06148 }
06149 
06150 //......................................................................
06151 
06152 void CDAnalysis::MuonNearFar()
06153 {
06154   MSG("CDAnalysis",Msg::kInfo) 
06155     <<" ** Running MuonNearFar method... **"<<endl;
06156 
06157   //open the output file for the histograms
06158   fOutFile=this->OpenFile(fRunNumber,"MuonNF");
06159 
06160   TH1F *h15_18All=new TH1F("h15_18All","h15_18All",1000,-2,75);
06161   h15_18All->GetXaxis()->SetTitle("SigCors");
06162   h15_18All->GetXaxis()->CenterTitle();
06163   h15_18All->GetYaxis()->SetTitle("");
06164   h15_18All->GetYaxis()->CenterTitle();
06165   h15_18All->SetFillColor(0);
06166   h15_18All->SetBit(TH1::kCanRebin);
06167 
06168   TH1F *h15_18=new TH1F("h15_18","h15_18",1000,-2,75);
06169   h15_18->GetXaxis()->SetTitle("SigCors");
06170   h15_18->GetXaxis()->CenterTitle();
06171   h15_18->GetYaxis()->SetTitle("");
06172   h15_18->GetYaxis()->CenterTitle();
06173   h15_18->SetFillColor(0);
06174   h15_18->SetBit(TH1::kCanRebin);
06175 
06176   TH1F *h15_18_O1=new TH1F("h15_18_O1","h15_18_O1",1000,-2,75);
06177   h15_18_O1->GetXaxis()->SetTitle("SigCors");
06178   h15_18_O1->GetXaxis()->CenterTitle();
06179   h15_18_O1->GetYaxis()->SetTitle("");
06180   h15_18_O1->GetYaxis()->CenterTitle();
06181   h15_18_O1->SetFillColor(0);
06182   h15_18_O1->SetBit(TH1::kCanRebin);
06183 
06184   TH1F *h15_18_E1=new TH1F("h15_18_E1","h15_18_E1",1000,-2,75);
06185   h15_18_E1->GetXaxis()->SetTitle("SigCors");
06186   h15_18_E1->GetXaxis()->CenterTitle();
06187   h15_18_E1->GetYaxis()->SetTitle("");
06188   h15_18_E1->GetYaxis()->CenterTitle();
06189   h15_18_E1->SetFillColor(0);
06190   h15_18_E1->SetBit(TH1::kCanRebin);
06191 
06192   TH1F *h15_18_O2=new TH1F("h15_18_O2","h15_18_O2",1000,-2,75);
06193   h15_18_O2->GetXaxis()->SetTitle("SigCors");
06194   h15_18_O2->GetXaxis()->CenterTitle();
06195   h15_18_O2->GetYaxis()->SetTitle("");
06196   h15_18_O2->GetYaxis()->CenterTitle();
06197   h15_18_O2->SetFillColor(0);
06198   h15_18_O2->SetBit(TH1::kCanRebin);
06199 
06200   TH1F *h15_18_E2=new TH1F("h15_18_E2","h15_18_E2",1000,-2,75);
06201   h15_18_E2->GetXaxis()->SetTitle("SigCors");
06202   h15_18_E2->GetXaxis()->CenterTitle();
06203   h15_18_E2->GetYaxis()->SetTitle("");
06204   h15_18_E2->GetYaxis()->CenterTitle();
06205   h15_18_E2->SetFillColor(0);
06206   h15_18_E2->SetBit(TH1::kCanRebin);
06207 
06208   //sum of all strip ends, normal and offset planes
06209   //tracked
06210   TProfile* pSigCorVsPlane=new TProfile("pSigCorVsPlane",
06211                                         "pSigCorVsPlane",
06212                                         62,0,62);
06213   TProfile* pSigCorVsOsPlane=new TProfile("pSigCorVsOsPlane",
06214                                           "pSigCorVsOsPlane",
06215                                           62,0,62);
06216 
06217   //xtalk + untracked hits
06218   TProfile* pSigCorVsPlaneX=new TProfile("pSigCorVsPlaneX",
06219                                          "pSigCorVsPlaneX",
06220                                          62,0,62);
06221   TProfile* pSigCorVsOsPlaneX=new TProfile("pSigCorVsOsPlaneX",
06222                                            "pSigCorVsOsPlaneX",
06223                                            62,0,62);
06224 
06225   //total
06226   TProfile* pSigCorVsPlaneT=new TProfile("pSigCorVsPlaneT",
06227                                          "pSigCorVsPlaneT",
06228                                          62,0,62);
06229   TProfile* pSigCorVsOsPlaneT=new TProfile("pSigCorVsOsPlaneT",
06230                                            "pSigCorVsOsPlaneT",
06231                                            62,0,62);
06232 
06233   //individual strip ends
06234   //tracked
06235   TProfile* pSigCorVsPlaneO1=new TProfile("pSigCorVsPlaneO1",
06236                                           "pSigCorVsPlaneO1",
06237                                           62,0,62);
06238   TProfile* pSigCorVsPlaneO2=new TProfile("pSigCorVsPlaneO2",
06239                                           "pSigCorVsPlaneO2",
06240                                           62,0,62);
06241   TProfile* pSigCorVsPlaneE1=new TProfile("pSigCorVsPlaneE1",
06242                                           "pSigCorVsPlaneE1",
06243                                           62,0,62);
06244   TProfile* pSigCorVsPlaneE2=new TProfile("pSigCorVsPlaneE2",
06245                                           "pSigCorVsPlaneE2",
06246                                           62,0,62);
06247   //xtalk + untracked hits
06248   TProfile* pSigCorVsPlaneO1X=new TProfile("pSigCorVsPlaneO1X",
06249                                           "pSigCorVsPlaneO1X",
06250                                           62,0,62);
06251   TProfile* pSigCorVsPlaneO2X=new TProfile("pSigCorVsPlaneO2X",
06252                                           "pSigCorVsPlaneO2X",
06253                                           62,0,62);
06254   TProfile* pSigCorVsPlaneE1X=new TProfile("pSigCorVsPlaneE1X",
06255                                           "pSigCorVsPlaneE1X",
06256                                           62,0,62);
06257   TProfile* pSigCorVsPlaneE2X=new TProfile("pSigCorVsPlaneE2X",
06258                                           "pSigCorVsPlaneE2X",
06259                                           62,0,62);
06260   //total
06261   TProfile* pSigCorVsPlaneO1T=new TProfile("pSigCorVsPlaneO1T",
06262                                           "pSigCorVsPlaneO1T",
06263                                           62,0,62);
06264   TProfile* pSigCorVsPlaneO2T=new TProfile("pSigCorVsPlaneO2T",
06265                                           "pSigCorVsPlaneO2T",
06266                                           62,0,62);
06267   TProfile* pSigCorVsPlaneE1T=new TProfile("pSigCorVsPlaneE1T",
06268                                           "pSigCorVsPlaneE1T",
06269                                           62,0,62);
06270   TProfile* pSigCorVsPlaneE2T=new TProfile("pSigCorVsPlaneE2T",
06271                                           "pSigCorVsPlaneE2T",
06272                                           62,0,62);
06273 
06274   //individual strip ends - offset planes
06275   //tracked
06276   TProfile* pSigCorVsOsPlaneO1=new TProfile("pSigCorVsOsPlaneO1",
06277                                             "pSigCorVsOsPlaneO1",
06278                                             62,0,62);
06279   TProfile* pSigCorVsOsPlaneO2=new TProfile("pSigCorVsOsPlaneO2",
06280                                             "pSigCorVsOsPlaneO2",
06281                                             62,0,62);
06282   TProfile* pSigCorVsOsPlaneE1=new TProfile("pSigCorVsOsPlaneE1",
06283                                             "pSigCorVsOsPlaneE1",
06284                                             62,0,62);
06285   TProfile* pSigCorVsOsPlaneE2=new TProfile("pSigCorVsOsPlaneE2",
06286                                             "pSigCorVsOsPlaneE2",
06287                                             62,0,62);
06288 
06289   //xtalk + untracked hits
06290   TProfile* pSigCorVsOsPlaneO1X=new TProfile("pSigCorVsOsPlaneO1X",
06291                                              "pSigCorVsOsPlaneO1X",
06292                                              62,0,62);
06293   TProfile* pSigCorVsOsPlaneO2X=new TProfile("pSigCorVsOsPlaneO2X",
06294                                             "pSigCorVsOsPlaneO2X",
06295                                             62,0,62);
06296   TProfile* pSigCorVsOsPlaneE1X=new TProfile("pSigCorVsOsPlaneE1X",
06297                                             "pSigCorVsOsPlaneE1X",
06298                                             62,0,62);
06299   TProfile* pSigCorVsOsPlaneE2X=new TProfile("pSigCorVsOsPlaneE2X",
06300                                             "pSigCorVsOsPlaneE2X",
06301                                             62,0,62);
06302   //total
06303   TProfile* pSigCorVsOsPlaneO1T=new TProfile("pSigCorVsOsPlaneO1T",
06304                                             "pSigCorVsOsPlaneO1T",
06305                                             62,0,62);
06306   TProfile* pSigCorVsOsPlaneO2T=new TProfile("pSigCorVsOsPlaneO2T",
06307                                             "pSigCorVsOsPlaneO2T",
06308                                             62,0,62);
06309   TProfile* pSigCorVsOsPlaneE1T=new TProfile("pSigCorVsOsPlaneE1T",
06310                                             "pSigCorVsOsPlaneE1T",
06311                                             62,0,62);
06312   TProfile* pSigCorVsOsPlaneE2T=new TProfile("pSigCorVsOsPlaneE2T",
06313                                             "pSigCorVsOsPlaneE2T",
06314                                             62,0,62);
06315 
06316 
06317   //near/far differences
06318   TProfile* pNearFarOdd=new TProfile("pNearFarOdd",
06319                                      "pNearFarOdd",62,0,62);
06320   TProfile* pNearFarEven=new TProfile("pNearFarEven",
06321                                       "pNearFarEven",62,0,62);
06322 
06323 
06324   vector<TProfile*> pSigCorVsDist;
06325   vector<Int_t> vWindowSize;
06326   vector<Float_t> bigAv;
06327   vector<Int_t> bigAvCounter;
06328   Float_t sum15_18=0;
06329   Float_t sum15_18Counter=0;
06330   Float_t sum15_18Mip=0;
06331   Float_t sum15_18MipCounter=0;
06332   Float_t sumSigCorTotal=0;
06333   Float_t sumSigCorTotalCounter=0;
06334   Float_t sumMipTotal=0;
06335   Float_t sumMipTotalCounter=0;
06336 
06337   //variables to calculate the energy dep for different stripends
06338   Float_t sum15_18_O1=0;
06339   Float_t sum15_18CounterO1=0;
06340   Float_t sum15_18_O2=0;
06341   Float_t sum15_18CounterO2=0;
06342   Float_t sum15_18_E1=0;
06343   Float_t sum15_18CounterE1=0;
06344   Float_t sum15_18_E2=0;
06345   Float_t sum15_18CounterE2=0;
06346 
06347   //num maps for all stripends
06348   map<Int_t,Float_t> num;
06349   map<Int_t,Float_t> numX;
06350   map<Int_t,Float_t> numT;
06351   map<Int_t,Float_t> numOs;
06352   map<Int_t,Float_t> numOsX;
06353   map<Int_t,Float_t> numOsT;
06354 
06355   //non-offset num maps for individual stripends
06356   map<Int_t,Float_t> numO1;
06357   map<Int_t,Float_t> numO1X;
06358   map<Int_t,Float_t> numO1T;
06359   map<Int_t,Float_t> numO2;
06360   map<Int_t,Float_t> numO2X;
06361   map<Int_t,Float_t> numO2T;
06362   map<Int_t,Float_t> numE1;
06363   map<Int_t,Float_t> numE1X;
06364   map<Int_t,Float_t> numE1T;
06365   map<Int_t,Float_t> numE2;
06366   map<Int_t,Float_t> numE2X;
06367   map<Int_t,Float_t> numE2T;
06368 
06369   //offset num maps for individual stripends
06370   map<Int_t,Float_t> numOsO1;
06371   map<Int_t,Float_t> numOsO1X;
06372   map<Int_t,Float_t> numOsO1T;
06373   map<Int_t,Float_t> numOsO2;
06374   map<Int_t,Float_t> numOsO2X;
06375   map<Int_t,Float_t> numOsO2T;
06376   map<Int_t,Float_t> numOsE1;
06377   map<Int_t,Float_t> numOsE1X;
06378   map<Int_t,Float_t> numOsE1T;
06379   map<Int_t,Float_t> numOsE2;
06380   map<Int_t,Float_t> numOsE2X;
06381   map<Int_t,Float_t> numOsE2T;
06382 
06383   Int_t noTrackCounter=0;
06384   Int_t passPidCounter=0;
06385  
06389   
06390   this->InitialiseLoopVariables();  
06391   
06392   for(Int_t event=0;event<fEvents;event++){
06393     
06394     this->SetLoopVariables(event);
06395 
06396     if (this->CutOnDeadChips()) continue;
06397     if (this->CutOnPid()) continue;
06398 
06399     //cut on not straight tracks
06400     //Double_t mainX1Cut=0.5;
06401     //if (!this->IsStraightTrack(mainX1Cut)){
06402     //continue;
06403     //}
06404 
06405     //count the number of events passing the pid
06406     passPidCounter++;
06407 
06408     map<Int_t,Int_t> numPlanesHit;
06409     map<Int_t,Int_t> numPlanesHit1;
06410     map<Int_t,Int_t> numPlanesHit2;
06411     map<Int_t,Int_t> numPlanesHitAll;
06412     map<Int_t,Float_t> planeSigCor;
06413     map<Int_t,Float_t> planeSigCorX;
06414     map<Int_t,Float_t> planeSigCorT;
06415     map<Int_t,Float_t> planeSigCorO1;    
06416     map<Int_t,Float_t> planeSigCorO1X;
06417     map<Int_t,Float_t> planeSigCorO1T;
06418     map<Int_t,Float_t> planeSigCorO2;
06419     map<Int_t,Float_t> planeSigCorO2X;
06420     map<Int_t,Float_t> planeSigCorO2T;
06421     map<Int_t,Float_t> planeSigCorE1;
06422     map<Int_t,Float_t> planeSigCorE1X;
06423     map<Int_t,Float_t> planeSigCorE1T;
06424     map<Int_t,Float_t> planeSigCorE2;
06425     map<Int_t,Float_t> planeSigCorE2X;
06426     map<Int_t,Float_t> planeSigCorE2T;
06427 
06428     map<Int_t,Float_t> planeMip;
06429     map<Int_t,Float_t> planeMipX;
06430     map<Int_t,Float_t> planeMipT;
06431 
06432     map<Int_t,Float_t> planePe;
06433     map<Int_t,Float_t> planeGreatestPe;
06434 
06435     //get tclones arrays for this snarl
06436     TClonesArray &cTrk=*fTrkHitInfo;
06437     Int_t numTrkHits=fTrkHitInfo->GetEntries();
06438     TClonesArray &cUnTrk = *fUnTrkHitInfo;
06439     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
06440     //CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
06441     TClonesArray &cXTalk = *fXTalkHits;
06442     Int_t numXTalkHits=fXTalkHits->GetEntries();
06443     //TClonesArray &cTruth = *fTruthHitInfo;
06444     Int_t numTruthHits=0;
06445     if (fTruthHitInfo) numTruthHits=fTruthHitInfo->GetEntries();
06446 
06447     //look for untracked big events
06448     if (numTrkHits<2 && numXTalkHits+numUnTrkHits>1){
06449       MSG("CDAnalysis",Msg::kDebug)
06450         <<"Event="<<event
06451         <<", Num hits: trk="<<numTrkHits<<", unTrk="<<numUnTrkHits
06452         <<", xtalk="<<numXTalkHits<<", truth="<<numTruthHits
06453         <<endl;
06454       noTrackCounter++;
06455       //continue;
06456     }
06457 
06459     //loop over the untracked hits in the snarl
06461     for (Int_t hit=0;hit<numUnTrkHits;hit++){
06462       //cast the tclonesarray up to a trackedhitinfo object
06463       CDTrackedHitInfo *hitInfo=
06464         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
06465 
06466       this->ReadInHitInfo(hitInfo);
06467 
06468       if (fPlane==0 && fChargeSigCor>1000){
06469         MSG("CDAnalysis",Msg::kDebug)
06470           <<"XTalk Event="<<event
06471           <<", fPlane="<<fPlane
06472           <<", fStrip="<<fStrip
06473           <<", fStripend="<<fStripend
06474           <<", fChargeAdc="<<fChargeAdc
06475           <<", fSigCor="<<fChargeSigCor<<endl;
06476       }
06477 
06478       //cut out the bad channels
06479       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
06480 
06481       //count the number of planes hit
06482       numPlanesHitAll[fPlane]++;
06483 
06484       //check the channel's sanity
06485       this->StandardSanityChecks();
06486 
06487       //add up the charge of the hits in each plane
06488       planeSigCorX[fPlane]+=fChargeSigCor;
06489       planeSigCorT[fPlane]+=fChargeSigCor;
06490       planeMipX[fPlane]+=fChargeMip;
06491       planeMipT[fPlane]+=fChargeMip;
06492       if (fO1) planeSigCorO1X[fPlane]+=fChargeSigCor;
06493       if (fO2) planeSigCorO2X[fPlane]+=fChargeSigCor;
06494       if (fE1) planeSigCorE1X[fPlane]+=fChargeSigCor;
06495       if (fE2) planeSigCorE2X[fPlane]+=fChargeSigCor;
06496       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
06497       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
06498       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
06499       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
06500 
06501       if (fChargePe>planeGreatestPe[fPlane]) planeGreatestPe[fPlane]=
06502                                                fChargePe;
06503     }
06504 
06506     //loop over xtalk hits in the snarl
06508     for (Int_t hit=0;hit<numXTalkHits;hit++){
06509       CDXTalkHitInfo *hitInfo=
06510         dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
06511 
06512       this->ReadInHitInfo(hitInfo);
06513       
06514       //cut out the bad channels
06515       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
06516 
06517       //count the number of planes hit
06518       numPlanesHitAll[fPlane]++;
06519 
06520       //check the channel's sanity
06521       this->StandardSanityChecks();
06522 
06523       //add up the charge of the hits in each plane
06524       planeSigCorX[fPlane]+=fChargeSigCor;
06525       planeSigCorT[fPlane]+=fChargeSigCor;
06526       planeMipX[fPlane]+=fChargeMip;
06527       planeMipT[fPlane]+=fChargeMip;
06528       if (fO1) planeSigCorO1X[fPlane]+=fChargeSigCor;
06529       if (fO2) planeSigCorO2X[fPlane]+=fChargeSigCor;
06530       if (fE1) planeSigCorE1X[fPlane]+=fChargeSigCor;
06531       if (fE2) planeSigCorE2X[fPlane]+=fChargeSigCor;
06532       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
06533       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
06534       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
06535       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
06536 
06537       if (fChargePe>planeGreatestPe[fPlane]) planeGreatestPe[fPlane]=
06538                                                fChargePe;
06539     }
06540 
06541     Bool_t lastPlaneO1Hit=false;
06542     Bool_t lastPlaneO2Hit=false;
06543     Bool_t lastPlaneE1Hit=false;
06544     Bool_t lastPlaneE2Hit=false;
06545     Int_t previousfLastPlane=-1;
06546 
06548     //loop over the tracked hits
06550     for (Int_t hit=0;hit<numTrkHits;hit++){
06551       CDTrackedHitInfo *trackedHitInfo=
06552         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
06553           
06554       this->ReadInHitInfo(trackedHitInfo);
06555 
06556       //cut out the bad channels
06557       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
06558 
06559       //check the channel's sanity
06560       this->StandardSanityChecks();
06561 
06562       //calculate the first and last planes
06563       this->CalcFirstLastPlane(fPlane);
06564 
06565       //count the number of planes hit
06566       numPlanesHit[fPlane]++;
06567       numPlanesHitAll[fPlane]++;
06568 
06569      if (fLastPlane==fPlane && fPlane%2==0){
06570 
06571         //check if a new last plane has been found
06572         if (fLastPlane!=previousfLastPlane){
06573           lastPlaneE1Hit=false;
06574           lastPlaneE2Hit=false;
06575         }
06576         previousfLastPlane=fLastPlane;
06577 
06578         //check which stripend to set to true
06579         if (fStripend==1) lastPlaneE1Hit=true;
06580         if (fStripend==2) lastPlaneE2Hit=true;
06581 
06582         //set the hits in the other plane to be false
06583         lastPlaneO1Hit=false;
06584         lastPlaneO2Hit=false;
06585         MSG("CDAnalysis",Msg::kVerbose)
06586           <<"ev="<<event
06587           <<", last="<<fLastPlane
06588           <<", pl="<<fPlane
06589           <<", se="<<fStripend
06590           <<", E1="<<lastPlaneE1Hit
06591           <<", E2="<<lastPlaneE2Hit
06592           <<", O1="<<lastPlaneO1Hit
06593           <<", O2="<<lastPlaneO2Hit<<endl;
06594       }
06595       else if (fLastPlane==fPlane && fPlane%2==1){
06596 
06597         //check if a new last plane has been found
06598         if (fLastPlane!=previousfLastPlane){
06599           lastPlaneO1Hit=false;
06600           lastPlaneO2Hit=false;
06601         }
06602         previousfLastPlane=fLastPlane;
06603 
06604         //check which stripend to set to true
06605         if (fStripend==1) lastPlaneO1Hit=true;
06606         if (fStripend==2) lastPlaneO2Hit=true;
06607 
06608         //set the hits in the other plane to be false
06609         lastPlaneE1Hit=false;
06610         lastPlaneE2Hit=false;
06611 
06612         MSG("CDAnalysis",Msg::kVerbose)
06613           <<"ev="<<event
06614           <<", last="<<fLastPlane
06615           <<", pl="<<fPlane
06616           <<", se="<<fStripend
06617           <<", E1="<<lastPlaneE1Hit
06618           <<", E2="<<lastPlaneE2Hit
06619           <<", O1="<<lastPlaneO1Hit
06620           <<", O2="<<lastPlaneO2Hit<<endl;
06621       }
06622 
06623       //add up the charge of the hits in each plane
06624       planeSigCor[fPlane]+=fChargeSigCor;
06625       planeSigCorT[fPlane]+=fChargeSigCor;
06626       planeMip[fPlane]+=fChargeMip;
06627       planeMipT[fPlane]+=fChargeMip;
06628       if (fChargePe>planeGreatestPe[fPlane]) planeGreatestPe[fPlane]=
06629                                                fChargePe;
06630       planePe[fPlane]+=fChargePe;
06631       if (fO1) planeSigCorO1[fPlane]+=fChargeSigCor;
06632       if (fO2) planeSigCorO2[fPlane]+=fChargeSigCor;
06633       if (fE1) planeSigCorE1[fPlane]+=fChargeSigCor;
06634       if (fE2) planeSigCorE2[fPlane]+=fChargeSigCor;
06635       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
06636       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
06637       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
06638       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
06639     }
06641     //end of loop over the tracked hits
06643 
06644     //make sure that the first plane makes sense and was actually set
06645     if (fFirstPlane<0 || fFirstPlane>59) continue;
06646 
06647     //calc the last plane on the track with no xtalk
06648     //Int_t lastPlaneNoXTalk=this->CalcLastPlaneOnTrkNoXTalk();
06649 
06650     //make event length cuts
06651     if (this->CutOnEventLength()) continue;
06652     //make track quality cuts
06653     if (this->CutOnTrackQuality()) continue;
06654 
06656     //section for response
06658     const Int_t os=fLastPlane;
06659 
06660     //must fill the profs before looping over the maps because
06661     //zeros will get added to the maps at the window stage!
06662     //fill profs for all stripends
06663     this->FillProfHisto(pSigCorVsPlane,num,planeSigCor);
06664     this->FillProfHisto(pSigCorVsPlaneX,numX,planeSigCorX);
06665     this->FillProfHisto(pSigCorVsPlaneT,numT,planeSigCorT);
06666     //offset
06667     this->FillProfHisto(pSigCorVsOsPlane,numOs,planeSigCor,os);
06668     this->FillProfHisto(pSigCorVsOsPlaneX,numOsX,planeSigCorX,os);
06669     this->FillProfHisto(pSigCorVsOsPlaneT,numOsT,planeSigCorT,os);
06670 
06671     //fill non-offset profs for individual stripends
06672     this->FillProfHisto(pSigCorVsPlaneO1,numO1,planeSigCorO1);
06673     this->FillProfHisto(pSigCorVsPlaneO1X,numO1X,planeSigCorO1X);
06674     this->FillProfHisto(pSigCorVsPlaneO1T,numO1T,planeSigCorO1T);
06675     this->FillProfHisto(pSigCorVsPlaneO2,numO2,planeSigCorO2);
06676     this->FillProfHisto(pSigCorVsPlaneO2X,numO2X,planeSigCorO2X);
06677     this->FillProfHisto(pSigCorVsPlaneO2T,numO2T,planeSigCorO2T);
06678     this->FillProfHisto(pSigCorVsPlaneE1,numE1,planeSigCorE1);
06679     this->FillProfHisto(pSigCorVsPlaneE1X,numE1X,planeSigCorE1X);
06680     this->FillProfHisto(pSigCorVsPlaneE1T,numE1T,planeSigCorE1T);
06681     this->FillProfHisto(pSigCorVsPlaneE2,numE2,planeSigCorE2);
06682     this->FillProfHisto(pSigCorVsPlaneE2X,numE2X,planeSigCorE2X);
06683     this->FillProfHisto(pSigCorVsPlaneE2T,numE2T,planeSigCorE2T);
06684 
06685     //fill offset profs for individual stripends
06686     this->FillProfHisto(pSigCorVsOsPlaneO1,numOsO1,planeSigCorO1,os);
06687     this->FillProfHisto(pSigCorVsOsPlaneO1X,numOsO1X,planeSigCorO1X,os);
06688     this->FillProfHisto(pSigCorVsOsPlaneO1T,numOsO1T,planeSigCorO1T,os);
06689     this->FillProfHisto(pSigCorVsOsPlaneO2,numOsO2,planeSigCorO2,os);
06690     this->FillProfHisto(pSigCorVsOsPlaneO2X,numOsO2X,planeSigCorO2X,os);
06691     this->FillProfHisto(pSigCorVsOsPlaneO2T,numOsO2T,planeSigCorO2T,os);
06692     this->FillProfHisto(pSigCorVsOsPlaneE1,numOsE1,planeSigCorE1,os);
06693     this->FillProfHisto(pSigCorVsOsPlaneE1X,numOsE1X,planeSigCorE1X,os);
06694     this->FillProfHisto(pSigCorVsOsPlaneE1T,numOsE1T,planeSigCorE1T,os);
06695     this->FillProfHisto(pSigCorVsOsPlaneE2,numOsE2,planeSigCorE2,os);
06696     this->FillProfHisto(pSigCorVsOsPlaneE2X,numOsE2X,planeSigCorE2X,os);
06697     this->FillProfHisto(pSigCorVsOsPlaneE2T,numOsE2T,planeSigCorE2T,os);
06698 
06700     //section for total event sigcor and mips
06702     Float_t localSumSigCorTotal=0;
06703     Float_t localSumSigCorTotalCounter=0;
06704     for (map<Int_t,Float_t>::iterator sig=planeSigCorT.begin();
06705          sig!=planeSigCorT.end();++sig){
06706       localSumSigCorTotal+=sig->second;
06707       localSumSigCorTotalCounter++;
06708     }
06709 
06710     //add total of this event to the sum of all events 
06711     if (localSumSigCorTotalCounter!=0){
06712       sumSigCorTotal+=localSumSigCorTotal;
06713       sumSigCorTotalCounter++;
06714     }
06715 
06716     Float_t localSumMipTotal=0;
06717     Float_t localSumMipTotalCounter=0;
06718     for (map<Int_t,Float_t>::iterator sig=planeMipT.begin();
06719          sig!=planeMipT.end();++sig){
06720       localSumMipTotal+=sig->second;
06721       localSumMipTotalCounter++;
06722     }
06723 
06724     //add total of this event to the sum of all events 
06725     if (localSumMipTotalCounter!=0){
06726       sumMipTotal+=localSumMipTotal;
06727       sumMipTotalCounter++;
06728     }
06729 
06731     //section for sliding window
06733     Int_t minEventLength=35;
06734     if (fLastPlane<minEventLength) continue;
06735 
06736     //initialise the profile histos
06737     static Bool_t firstTime=true;
06738     if (firstTime){
06739       for (Int_t p=15;p>1;p--){
06740         vWindowSize.push_back(p);
06741         bigAv.push_back(0);
06742         bigAvCounter.push_back(0);
06743       }
06744 
06745       for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
06746            windowSize!=vWindowSize.end();++windowSize){
06747         
06748         string sName=Form("%d",*windowSize);
06749         pSigCorVsDist.push_back
06750           (new TProfile(("pSigCorVsDist"+sName).c_str(),
06751                         ("pSigCorVsDist"+sName).c_str(),100,-2,40));
06752       }
06753     }
06754     firstTime=false;
06755 
06756     vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
06757     vector<Float_t>::iterator av=bigAv.begin();
06758     vector<Int_t>::iterator count=bigAvCounter.begin();
06759     Float_t localSum15_18=0;
06760     Float_t localSum15_18Counter=0;
06761     Float_t localSum15_18Mip=0;
06762     Float_t localSum15_18MipCounter=0;
06763 
06764     Float_t localSum15_18_O1=0;
06765     Float_t localSum15_18CounterO1=0;
06766     Float_t localSum15_18_O2=0;
06767     Float_t localSum15_18CounterO2=0;
06768     Float_t localSum15_18_E1=0;
06769     Float_t localSum15_18CounterE1=0;
06770     Float_t localSum15_18_E2=0;
06771     Float_t localSum15_18CounterE2=0;
06772     Bool_t oneMoreEvenPlane=false;
06773 
06774     //loop over the different window sizes
06775     for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
06776          windowSize!=vWindowSize.end();++windowSize){
06777       
06778       Float_t localSumO1=0;
06779       Float_t localSumCounterO1=0;
06780       Float_t localSumO2=0;
06781       Float_t localSumCounterO2=0;
06782       Float_t localSumE1=0;
06783       Float_t localSumCounterE1=0;
06784       Float_t localSumE2=0;
06785       Float_t localSumCounterE2=0;
06786 
06787       //slide the window along from the end to 40-windowSize
06788       for (Int_t p=0;p<minEventLength-*windowSize;p++){
06789         Int_t windowStart=fLastPlane-p;
06790 
06791         MSG("CDAnalysis",Msg::kVerbose)
06792           <<"Window size="<<*windowSize
06793           <<", window start="<<windowStart
06794           <<endl;
06795 
06796         //loop through the hits in the window
06797         for (Int_t i=0;i<*windowSize;i++){
06798           Int_t plane=windowStart-i;
06799           
06800           //cut out planes that are greater than the last plane
06801           //in the view - ie the zeros at the end
06802           Bool_t doZeroCorrection=false;
06803           if (doZeroCorrection && 
06804               ((plane%2==0 && plane>fLastPlaneEven) || 
06805                (plane%2!=0 && plane>fLastPlaneOdd))){
06806             MSG("CDAnalysis",Msg::kVerbose)
06807               <<"Not using: Event="<<event
06808               <<", pl="<<plane
06809               <<", sigCor="<<planeSigCorT[plane]
06810               <<", fLastPlane="<<fLastPlane
06811               <<", fLastPlSig="<<planeSigCorT[fLastPlane]
06812               <<", fLastPlOdd="<<fLastPlaneOdd
06813               <<", fLastPlEven="<<fLastPlaneEven
06814               <<endl;
06815           }
06816           else{
06817 
06818             //calculate the best window value
06819             //if fLP=48 then the first plane included is 30
06820             //this is actually the 19th from the end of the track
06821             if (*windowSize==15 && windowStart==fLastPlane-18){
06822               localSum15_18+=planeSigCorT[plane];//total including xtalk
06823               localSum15_18Counter++;
06824               localSum15_18Mip+=planeMipT[plane];//total including xtalk
06825               localSum15_18MipCounter++;
06826 
06827               //a 15 plane window means 7 even and 8 odd or vice versa!
06828               if (windowStart%2==0) oneMoreEvenPlane=true;
06829 
06830               //look at the individual stripends
06831               if (plane%2==0){//even
06832                 localSum15_18_E1+=planeSigCorE1T[plane];
06833                 localSum15_18CounterE1++;
06834                 localSum15_18_E2+=planeSigCorE2T[plane];
06835                 localSum15_18CounterE2++;
06836               }
06837               else if (plane%2==1){//odd
06838                 localSum15_18_O1+=planeSigCorO1T[plane];
06839                 localSum15_18CounterO1++;
06840                 localSum15_18_O2+=planeSigCorO2T[plane];
06841                 localSum15_18CounterO2++;
06842               }
06843             }
06844 
06845 
06846             if (*windowSize==15){
06847               //look at the individual stripends
06848               if (plane%2==0){//even
06849                 localSumE1+=planeSigCorE1T[plane];
06850                 localSumCounterE1++;
06851                 localSumE2+=planeSigCorE2T[plane];
06852                 localSumCounterE2++;
06853               }
06854               else if (plane%2==1){//odd
06855                 localSumO1+=planeSigCorO1T[plane];
06856                 localSumCounterO1++;
06857                 localSumO2+=planeSigCorO2T[plane];
06858                 localSumCounterO2++;
06859               }
06860             }
06861 
06862             (*prof)->Fill(p,planeSigCorT[plane]);
06863             (*av)+=planeSigCorT[plane];
06864             (*count)++;
06865           }
06866         }
06867 
06868         //calculate the near/far differences
06869         if (*windowSize==15){
06870 
06871           //a 15 plane window means 7 even and 8 odd or vice versa!
06872           Bool_t moreEven=false;
06873           if (windowStart%2==0) moreEven=true;
06874           Float_t divEven=1;
06875           Float_t divOdd=1;
06876 
06877           if (moreEven) {divEven=8; divOdd=7;}
06878           else {divEven=7; divOdd=8;}
06879 
06880           MAXMSG("CDAnalysis",Msg::kVerbose,70)
06881             <<"WindowStart="<<windowStart<<", moreEven="<<moreEven
06882             <<", divEven="<<divEven<<", divOdd="<<divOdd
06883             <<endl;
06884     
06885           Float_t largestOdd=localSumO1/divOdd;
06886           Float_t largestEven=localSumE1/divEven;
06887           
06888           if (localSumO2/divOdd>localSumO1/divOdd){
06889             largestOdd=localSumO2/divOdd;
06890           }
06891           if (localSumE2/divEven>localSumE1/divEven){
06892             largestEven=localSumE2/divEven;
06893           }
06894 
06895           //protect fpe
06896           if (largestOdd>0){
06897             Float_t diffNearFarOdd=100*(localSumO1/divOdd-
06898                                         localSumO2/divOdd)/largestOdd;
06899             pNearFarOdd->Fill(p,diffNearFarOdd);
06900           }
06901           if (largestEven>0){
06902             Float_t diffNearFarEven=100*(localSumE1/divEven-
06903                                          localSumE2/divEven
06904                                          )/largestEven;
06905             pNearFarEven->Fill(p,diffNearFarEven);
06906           }      
06907         }
06908       }
06909       av++;
06910       count++;
06911       prof++;
06912     }
06913 
06914     if (localSum15_18Counter!=0){
06915       h15_18All->Fill(localSum15_18);
06916       h15_18->Fill(localSum15_18/15);
06917       sum15_18+=localSum15_18;//add this event's energy on to total
06918       sum15_18Counter++;
06919       sum15_18Mip+=localSum15_18Mip;
06920       sum15_18MipCounter++;
06921     }
06922     else{
06923       MAXMSG("CDAnalysis",Msg::kInfo,40)
06924         <<"Event="<<event<<", strange 15_18="<<localSum15_18
06925         <<", counter="<<localSum15_18Counter<<endl;
06926     }
06927 
06928     Float_t divEven=1;
06929     Float_t divOdd=1;
06930     
06931     if (oneMoreEvenPlane) {divEven=8; divOdd=7;}
06932     else {divEven=7; divOdd=8;}
06933     
06934     h15_18_O1->Fill(localSum15_18_O1/divOdd);
06935     sum15_18_O1+=localSum15_18_O1/divOdd;
06936     sum15_18CounterO1++;
06937     h15_18_O2->Fill(localSum15_18_O2/divOdd);
06938     sum15_18_O2+=localSum15_18_O2/divOdd;
06939     sum15_18CounterO2++;
06940     
06941     h15_18_E1->Fill(localSum15_18_E1/divEven);
06942     sum15_18_E1+=localSum15_18_E1/divEven;
06943     sum15_18CounterE1++;
06944     h15_18_E2->Fill(localSum15_18_E2/divEven);
06945     sum15_18_E2+=localSum15_18_E2/divEven;
06946     sum15_18CounterE2++;
06947 
06948   }//end of for                                       
06949   
06953 
06954   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06955 
06956   //turn off the stats box printing
06957   gStyle->SetOptStat(0);
06958 
06959   //all stripends
06960   string sTitle="Energy Deposition (SigCor, all Stripends)";
06961   string sXTitle="Distance from end of track (planes)";
06962   this->DrawResponsePlot(sTitle,pSigCorVsPlane,pSigCorVsPlaneX,
06963                          pSigCorVsPlaneT,num,numX,numT);
06964   sTitle="Energy Deposition Vs Distance (SigCor, all Stripends)";
06965   this->DrawResponsePlot(sTitle,pSigCorVsOsPlane,pSigCorVsOsPlaneX,
06966                          pSigCorVsOsPlaneT,numOs,numOsX,numOsT,sXTitle);
06967 
06968   //non-offset planes
06969   sTitle="Energy Deposition (SigCor in Odd Planes FD stripend)";
06970   this->DrawResponsePlot(sTitle,pSigCorVsPlaneO1,pSigCorVsPlaneO1X,
06971                          pSigCorVsPlaneO1T,numO1,numO1X,numO1T);
06972 
06973   sTitle="Energy Deposition (SigCor in Odd Planes ND stripend)";
06974   this->DrawResponsePlot(sTitle,pSigCorVsPlaneO2,pSigCorVsPlaneO2X,
06975                          pSigCorVsPlaneO2T,numO2,numO2X,numO2T);
06976 
06977   sTitle="Energy Deposition (SigCor in Even Planes FD stripend)";
06978   this->DrawResponsePlot(sTitle,pSigCorVsPlaneE1,pSigCorVsPlaneE1X,
06979                          pSigCorVsPlaneE1T,numE1,numE1X,numE1T);
06980 
06981   sTitle="Energy Deposition (SigCor in Even Planes ND stripend)";
06982   this->DrawResponsePlot(sTitle,pSigCorVsPlaneE2,pSigCorVsPlaneE2X,
06983                          pSigCorVsPlaneE2T,numE2,numE2X,numE2T);
06984 
06985   //offset planes
06986   sTitle="Energy Deposition Vs Distance (SigCor in Odd Planes FD stripend)";
06987   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneO1,pSigCorVsOsPlaneO1X,
06988                          pSigCorVsOsPlaneO1T,numOsO1,numOsO1X,numOsO1T,
06989                          sXTitle);
06990 
06991   sTitle="Energy Deposition Vs Distance (SigCor in Odd Planes ND stripend)";
06992   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneO2,pSigCorVsOsPlaneO2X,
06993                          pSigCorVsOsPlaneO2T,numOsO2,numOsO2X,numOsO2T,
06994                          sXTitle);
06995 
06996   sTitle="Energy Deposition Vs Distance (SigCor in Even Planes FD stripend)";
06997   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneE1,pSigCorVsOsPlaneE1X,
06998                          pSigCorVsOsPlaneE1T,numOsE1,numOsE1X,numOsE1T,
06999                          sXTitle);
07000 
07001   sTitle="Energy Deposition Vs Distance (SigCor in Even Planes ND stripend)";
07002   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneE2,pSigCorVsOsPlaneE2X,
07003                          pSigCorVsOsPlaneE2T,numOsE2,numOsE2X,numOsE2T,
07004                          sXTitle);
07005 
07006   //turn on the stats box printing
07007   gStyle->SetOptStat(111111);
07008 
07009   TCanvas *c15_18=new TCanvas("c15_18","15_18",0,0,1200,800);
07010   c15_18->SetFillColor(0);
07011   c15_18->Divide(2,3);
07012   c15_18->cd(1);
07013   h15_18->Draw();
07014   c15_18->cd(2);
07015   h15_18All->Draw();
07016   c15_18->cd(3);
07017   h15_18_O1->Draw();
07018   c15_18->cd(4);
07019   h15_18_O2->Draw();
07020   c15_18->cd(5);
07021   h15_18_E1->Draw();
07022   c15_18->cd(6);
07023   h15_18_E2->Draw();
07024 
07025   TCanvas *cNearFar=new TCanvas("cNearFar","NearFar",0,0,1200,800);
07026   cNearFar->SetFillColor(0);
07027   cNearFar->Divide(2,3);
07028   cNearFar->cd(1);
07029   pNearFarOdd->Draw();
07030   cNearFar->cd(2);
07031   pNearFarEven->Draw();
07032 
07033   if (sum15_18Counter!=0){
07034     MSG("CDAnalysis",Msg::kInfo) 
07035       <<endl
07036       <<" ** Calibration Summary **"<<endl
07037       <<"SigCor in sliding window 15_18:"<<endl
07038       <<"    SigCor dep="<<sum15_18<<" (N="<<sum15_18Counter<<")"<<endl
07039       <<"    Av SigCor dep="<<sum15_18/sum15_18Counter
07040       <<" +/- "<<100*(h15_18->GetRMS()/sqrt(h15_18->GetEntries()))/
07041       h15_18->GetMean()<<"%"<<endl
07042       <<"    Av SigCor dep per plane="<<(sum15_18/sum15_18Counter)/15
07043       <<" +/- "<<100*(h15_18->GetRMS()/sqrt(h15_18->GetEntries()))/
07044       h15_18->GetMean()<<"%"<<endl
07045       <<"MIPs in sliding window 15_18:"<<endl
07046       <<"    MIPs dep="<<sum15_18Mip
07047       <<" (N="<<sum15_18MipCounter<<")"<<endl
07048       <<"    Av MIPs dep="<<sum15_18Mip/sum15_18MipCounter
07049       <<endl;
07050     if (sumSigCorTotalCounter!=0){
07051       MSG("CDAnalysis",Msg::kInfo) 
07052         <<"SigCor of whole event:"<<endl
07053         <<"    Sum of SigCor dep="<<sumSigCorTotal
07054         <<" (N="<<sumSigCorTotalCounter<<")"<<endl
07055         <<"    Av sigCor dep="
07056         <<sumSigCorTotal/sumSigCorTotalCounter<<endl
07057         <<"    1 sigCor="
07058         <<1800/(sumSigCorTotal/sumSigCorTotalCounter)<<" MeV"
07059         <<endl;
07060     }
07061     if (sumMipTotalCounter!=0){
07062       MSG("CDAnalysis",Msg::kInfo) 
07063         <<"MIPs of whole event:"<<endl
07064         <<"    Sum of MIPs dep="<<sumMipTotal
07065         <<" (N="<<sumMipTotalCounter<<")"<<endl
07066         <<"    Av MIPs dep="
07067         <<sumMipTotal/sumMipTotalCounter<<endl
07068         <<"    1 MIP="
07069         <<1800/(sumMipTotal/sumMipTotalCounter)<<" MeV"<<endl
07070         <<"    1 GeV="
07071         <<(sumMipTotal/sumMipTotalCounter)/1.8<<" MIPs"
07072         <<endl<<endl;
07073     }
07074   }
07075 
07076   if (sum15_18CounterO1!=0 && sum15_18CounterE1!=0){
07077     MSG("CDAnalysis",Msg::kInfo) 
07078       <<endl
07079       <<"SigCor in sliding window 15_18 in stripend 1:"<<endl
07080       <<" Odd planes:"<<endl
07081       <<"    SigCor dep="<<sum15_18_O1
07082       <<" (N="<<sum15_18CounterO1<<")"<<endl
07083       <<"    Av SigCor dep="<<sum15_18_O1/sum15_18CounterO1
07084       <<" +/- "<<h15_18_O1->GetRMS()/sqrt(h15_18_O1->GetEntries())
07085       <<" ("<<100*((h15_18_O1->GetRMS()/
07086                    sqrt(h15_18_O1->GetEntries()))/
07087                    h15_18_O1->GetMean())<<"%)"
07088       <<endl
07089       <<" Even planes:"<<endl
07090       <<"    SigCor dep="<<sum15_18_E1
07091       <<" (N="<<sum15_18CounterE1<<")"<<endl
07092       <<"    Av SigCor dep="<<sum15_18_E1/sum15_18CounterE1
07093       <<" +/- "<<h15_18_E1->GetRMS()/sqrt(h15_18_E1->GetEntries())
07094       <<" ("<<100*((h15_18_E1->GetRMS()/
07095                    sqrt(h15_18_E1->GetEntries()))/
07096                    h15_18_E1->GetMean())<<"%)"<<endl
07097       <<endl;
07098   }
07099   if (sum15_18CounterO2!=0 && sum15_18CounterE2!=0){
07100     MSG("CDAnalysis",Msg::kInfo) 
07101       <<endl
07102       <<"SigCor in sliding window 15_18 in stripend 2:"<<endl
07103       <<" Odd planes:"<<endl
07104       <<"    SigCor dep="<<sum15_18_O2
07105       <<" (N="<<sum15_18CounterO2<<")"<<endl
07106       <<"    Av SigCor dep="<<sum15_18_O2/sum15_18CounterO2
07107       <<" +/- "<<h15_18_O2->GetRMS()/sqrt(h15_18_O2->GetEntries())
07108       <<" ("<<100*((h15_18_O2->GetRMS()/
07109                    sqrt(h15_18_O2->GetEntries()))/
07110                    h15_18_O2->GetMean())<<"%)"
07111       <<endl
07112       <<" Even planes:"<<endl
07113       <<"    SigCor dep="<<sum15_18_E2
07114       <<" (N="<<sum15_18CounterE2<<")"<<endl
07115       <<"    Av SigCor dep="<<sum15_18_E2/sum15_18CounterE2
07116       <<" +/- "<<h15_18_E2->GetRMS()/sqrt(h15_18_E2->GetEntries())
07117       <<" ("<<100*((h15_18_E2->GetRMS()/
07118                    sqrt(h15_18_E2->GetEntries()))/
07119                    h15_18_E2->GetMean())<<"%)"<<endl
07120       <<endl;
07121   }
07122 
07123   //calculate the differences between near/far
07124   if (sum15_18CounterO2!=0 && sum15_18CounterE2!=0 &&
07125       sum15_18CounterO1!=0 && sum15_18CounterE1!=0){
07126 
07127     Float_t largestOdd=sum15_18_O1/sum15_18CounterO1;
07128     Float_t largestEven=sum15_18_E1/sum15_18CounterE1;
07129     Float_t diffOdd=sum15_18_O1/sum15_18CounterO1-
07130       sum15_18_O2/sum15_18CounterO2;
07131     Float_t diffEven=sum15_18_E1/sum15_18CounterE1-
07132       sum15_18_E2/sum15_18CounterE2;
07133 
07134     if (sum15_18_O2/sum15_18CounterO2>sum15_18_O1/sum15_18CounterO1) {
07135       largestOdd=sum15_18_O2/sum15_18CounterO2;
07136     }
07137     if (sum15_18_E2/sum15_18CounterE2>sum15_18_E1/sum15_18CounterE1) {
07138       largestEven=sum15_18_E2/sum15_18CounterE2;
07139     }
07140     
07141     MSG("CDAnalysis",Msg::kInfo) 
07142       <<endl
07143       <<"Difference between stripend 1 and 2 (1-2/largest):"<<endl
07144       <<" Odd planes:"<<endl
07145       <<"    Difference="<<diffOdd<<" ("<<100*diffOdd/largestOdd<<"%)"
07146       <<endl
07147       <<" Even planes:"<<endl
07148       <<"    Difference="<<diffEven<<" ("
07149       <<100*diffEven/largestEven<<"%)"
07150       <<endl;
07151   }
07152 
07153   MSG("CDAnalysis",Msg::kInfo) 
07154     <<" ** Finished MuonNearFar method **"<<endl;
07155 
07156 }
07157 
07158 //......................................................................
07159 
07160 Float_t CDAnalysis::ReCalibrate(Float_t chargeAdc,Int_t plane,
07161                                 Int_t strip,Int_t stripend) const
07162 {
07163   if (fDoReCalibration && fSimFlag==SimFlag::kData){
07164     MAXMSG("CDAnalysis",Msg::kInfo,10)
07165       <<"Running ReCalibrate: fSec="<<fSec
07166       <<", simFlag="<<fSimFlag<<endl;
07167     
07168     //get a calibrator
07169     Calibrator& cal=Calibrator::Instance();
07170     //VldTimeStamp (const time_t &t, const Int_t nsec)
07171     VldTimeStamp vldts(fSec,0);
07172     VldContext vc(Detector::kCalDet,fSimFlag,vldts);
07173     cal.ReInitialise(vc);
07174     MAXMSG("CDAnalysis",Msg::kVerbose,100)
07175       <<"Calibrator reinitialised sucessfully"<<endl;
07176     
07177     //get the seid
07178     PlexStripEndId seid(Detector::kCalDet,plane,strip,
07179                         static_cast<StripEnd::EStripEnd>(stripend));
07180     
07181     MAXMSG("CDAnalysis",Msg::kVerbose,100)
07182       <<"Now calibrating drift..."<<endl;
07183     //now calibrate: first drift, then sts
07184     Float_t tmpCharge=chargeAdc;
07185     tmpCharge=cal.GetDriftCorrected(tmpCharge,seid);
07186     MAXMSG("CDAnalysis",Msg::kVerbose,100)
07187     <<"Now calibrating sts..."<<endl;
07188     tmpCharge=cal.GetStripToStripCorrected(tmpCharge,seid);
07189     
07190     MAXMSG("CDAnalysis",Msg::kInfo,50)
07191       <<"ReCalibrate: fChargeSigCor="<<fChargeSigCor
07192       <<", newSigCor="<<tmpCharge
07193       <<", temperature="<<cal.GetTemperature()<<endl;
07194     
07195     //return the newly calibrated number
07196     return tmpCharge;
07197   }
07198   else {
07199     //just return the original value of sigcor
07200     return fChargeSigCor;
07201   }
07202 }
07203 
07204 //......................................................................
07205 
07206 void CDAnalysis::StoppingMuonCalibration()
07207 {
07208   //open the output file for the histograms
07209   fOutFile=this->OpenFile(fRunNumber,"StopMuCal");
07210 
07211   //set the recalibration flag
07212   fDoReCalibration=false;
07213 
07214   VldTimeStamp ts;
07215   cout<<"Time in secs right now is:"<<ts.GetSec()<<endl;
07217   Int_t minRunTime=4;//is:1112976714
07218   if (ts.GetSec()>minRunTime){
07219     //analyse the electrons and fill histos
07220     this->ElectronResponse();
07221   }
07222 
07223   MSG("CDAnalysis",Msg::kInfo) 
07224     <<" ** Running StoppingMuonCalibration method... **"<<endl;
07225 
07226   vector<TH1F*> meuHistos(60);
07227   vector<TH1F*> sigCorNoPLCorHistos(60);
07228   //vector<TH1F*> adcNoPLCorHistos(60);//no adc info stored: June 2007
07229   for (Int_t i=0;i<60;i++){
07230     string sName="hMeuPlane";
07231     string sNameSigCor="hSigCorNoPLCorPlane";
07232     //string sNameAdc="hAdcNoPLCorPlane";
07233     string sNum=Form("%d",i);
07234     sName+=sNum;
07235     sNameSigCor+=sNum;
07236     //sNameAdc+=sNum;
07237 
07238     meuHistos[i]=new TH1F(sName.c_str(),sName.c_str(),300,-2,3000);
07239     meuHistos[i]->SetBit(TH1::kCanRebin);//leave this as is June/07
07240     //meuHistos[i]->Print();
07241 
07242     //added sigcor in June 2007
07243     sigCorNoPLCorHistos[i]=new TH1F
07244       (sNameSigCor.c_str(),sNameSigCor.c_str(),300,-2,3000);
07245     //adcNoPLCorHistos[i]=new TH1F
07246     //(sName.c_str(),sName.c_str(),300,-2,3000);
07247   }
07248   
07249   TH1F *hMeu=new TH1F("hMeu","hMeu",1000,-2,1000);
07250   hMeu->GetXaxis()->SetTitle("SigCors");
07251   hMeu->GetXaxis()->CenterTitle();
07252   hMeu->GetYaxis()->SetTitle("");
07253   hMeu->GetYaxis()->CenterTitle();
07254   hMeu->SetFillColor(0);
07255   hMeu->SetBit(TH1::kCanRebin);
07256 
07257   TH1F* hGeVPerMeu=new TH1F("hGeVPerMeu","hGeVPerMeu",3000,-0.001,0.3);
07258   hGeVPerMeu->SetFillColor(0);
07259   hGeVPerMeu->SetTitle("GeV/MEU");
07260   hGeVPerMeu->GetXaxis()->SetTitle("GeV/MEU");
07261   hGeVPerMeu->GetXaxis()->CenterTitle();
07262 
07263   TH1F *hMeuPLCor=new TH1F("hMeuPLCor","hMeuPLCor",1000,-2,1000);
07264   hMeuPLCor->GetXaxis()->SetTitle("SigCors");
07265   hMeuPLCor->GetXaxis()->CenterTitle();
07266   hMeuPLCor->GetYaxis()->SetTitle("");
07267   hMeuPLCor->GetYaxis()->CenterTitle();
07268   hMeuPLCor->SetFillColor(0);
07269   hMeuPLCor->SetBit(TH1::kCanRebin);
07270 
07271   TH1F *hMeuTruePLCor=new TH1F("hMeuTruePLCor","hMeuTruePLCor",
07272                                1000,-2,1000);
07273   hMeuTruePLCor->GetXaxis()->SetTitle("SigCors");
07274   hMeuTruePLCor->GetXaxis()->CenterTitle();
07275   hMeuTruePLCor->GetYaxis()->SetTitle("");
07276   hMeuTruePLCor->GetYaxis()->CenterTitle();
07277   hMeuTruePLCor->SetFillColor(0);
07278   hMeuTruePLCor->SetBit(TH1::kCanRebin);
07279 
07280   TH1F *hMeuOnlyEventLengthCut=new TH1F("hMeuOnlyEventLengthCut",
07281                                         "hMeuOnlyEventLengthCut",
07282                                         1000,-2,1000);
07283   hMeuOnlyEventLengthCut->GetXaxis()->SetTitle("SigCors");
07284   hMeuOnlyEventLengthCut->GetXaxis()->CenterTitle();
07285   hMeuOnlyEventLengthCut->GetYaxis()->SetTitle("");
07286   hMeuOnlyEventLengthCut->GetYaxis()->CenterTitle();
07287   hMeuOnlyEventLengthCut->SetFillColor(0);
07288   hMeuOnlyEventLengthCut->SetBit(TH1::kCanRebin);
07289 
07290   TH1F *hMeuOnlyEL_FidCut=new TH1F("hMeuOnlyEL_FidCut",
07291                                    "hMeuOnlyEL_FidCut",
07292                                    1000,-2,1000);
07293   hMeuOnlyEL_FidCut->GetXaxis()->SetTitle("SigCors");
07294   hMeuOnlyEL_FidCut->GetXaxis()->CenterTitle();
07295   hMeuOnlyEL_FidCut->GetYaxis()->SetTitle("");
07296   hMeuOnlyEL_FidCut->GetYaxis()->CenterTitle();
07297   hMeuOnlyEL_FidCut->SetFillColor(0);
07298   hMeuOnlyEL_FidCut->SetBit(TH1::kCanRebin);
07299 
07300   TH1F *hMeuOnlyEL_Fid_TimeCut=new TH1F("hMeuOnlyEL_Fid_TimeCut",
07301                                         "hMeuOnlyEL_Fid_TimeCut",
07302                                         1000,-2,1000);
07303   hMeuOnlyEL_Fid_TimeCut->GetXaxis()->SetTitle("SigCors");
07304   hMeuOnlyEL_Fid_TimeCut->GetXaxis()->CenterTitle();
07305   hMeuOnlyEL_Fid_TimeCut->GetYaxis()->SetTitle("");
07306   hMeuOnlyEL_Fid_TimeCut->GetYaxis()->CenterTitle();
07307   hMeuOnlyEL_Fid_TimeCut->SetFillColor(0);
07308   hMeuOnlyEL_Fid_TimeCut->SetBit(TH1::kCanRebin);
07309 
07310   TH1F *hMeuOnlyEL_TimeCut=new TH1F("hMeuOnlyEL_TimeCut",
07311                                    "hMeuOnlyEL_TimeCut",
07312                                    1000,-2,1000);
07313   hMeuOnlyEL_TimeCut->GetXaxis()->SetTitle("SigCors");
07314   hMeuOnlyEL_TimeCut->GetXaxis()->CenterTitle();
07315   hMeuOnlyEL_TimeCut->GetYaxis()->SetTitle("");
07316   hMeuOnlyEL_TimeCut->GetYaxis()->CenterTitle();
07317   hMeuOnlyEL_TimeCut->SetFillColor(0);
07318   hMeuOnlyEL_TimeCut->SetBit(TH1::kCanRebin);
07319 
07320   TH1F *hMeuOnlyEL_HppCut=new TH1F("hMeuOnlyEL_HppCut",
07321                                    "hMeuOnlyEL_HppCut",
07322                                    1000,-2,1000);
07323   hMeuOnlyEL_HppCut->GetXaxis()->SetTitle("SigCors");
07324   hMeuOnlyEL_HppCut->GetXaxis()->CenterTitle();
07325   hMeuOnlyEL_HppCut->GetYaxis()->SetTitle("");
07326   hMeuOnlyEL_HppCut->GetYaxis()->CenterTitle();
07327   hMeuOnlyEL_HppCut->SetFillColor(0);
07328   hMeuOnlyEL_HppCut->SetBit(TH1::kCanRebin);
07329 
07330   TH1F *hMeuOnlyPID_EventLengthCut=new TH1F("hMeuOnlyPID_EventLengthCut",
07331                                         "hMeuOnlyPID_EventLengthCut",
07332                                         1000,-2,1000);
07333   hMeuOnlyPID_EventLengthCut->GetXaxis()->SetTitle("SigCors");
07334   hMeuOnlyPID_EventLengthCut->GetXaxis()->CenterTitle();
07335   hMeuOnlyPID_EventLengthCut->GetYaxis()->SetTitle("");
07336   hMeuOnlyPID_EventLengthCut->GetYaxis()->CenterTitle();
07337   hMeuOnlyPID_EventLengthCut->SetFillColor(0);
07338   hMeuOnlyPID_EventLengthCut->SetBit(TH1::kCanRebin);
07339 
07340   TH1F *hMeuOnlyPID_EL_FidCut=new TH1F("hMeuOnlyPID_EL_FidCut",
07341                                    "hMeuOnlyPID_EL_FidCut",
07342                                    1000,-2,1000);
07343   hMeuOnlyPID_EL_FidCut->GetXaxis()->SetTitle("SigCors");
07344   hMeuOnlyPID_EL_FidCut->GetXaxis()->CenterTitle();
07345   hMeuOnlyPID_EL_FidCut->GetYaxis()->SetTitle("");
07346   hMeuOnlyPID_EL_FidCut->GetYaxis()->CenterTitle();
07347   hMeuOnlyPID_EL_FidCut->SetFillColor(0);
07348   hMeuOnlyPID_EL_FidCut->SetBit(TH1::kCanRebin);
07349 
07350   TH1F *hMeuOnlyPID_EL_Fid_TimeCut=new TH1F("hMeuOnlyPID_EL_Fid_TimeCut",
07351                                         "hMeuOnlyPID_EL_Fid_TimeCut",
07352                                         1000,-2,1000);
07353   hMeuOnlyPID_EL_Fid_TimeCut->GetXaxis()->SetTitle("SigCors");
07354   hMeuOnlyPID_EL_Fid_TimeCut->GetXaxis()->CenterTitle();
07355   hMeuOnlyPID_EL_Fid_TimeCut->GetYaxis()->SetTitle("");
07356   hMeuOnlyPID_EL_Fid_TimeCut->GetYaxis()->CenterTitle();
07357   hMeuOnlyPID_EL_Fid_TimeCut->SetFillColor(0);
07358   hMeuOnlyPID_EL_Fid_TimeCut->SetBit(TH1::kCanRebin);
07359 
07360   TH1F *hMeuOnlyPID_EL_TimeCut=new TH1F("hMeuOnlyPID_EL_TimeCut",
07361                                    "hMeuOnlyPID_EL_TimeCut",
07362                                    1000,-2,1000);
07363   hMeuOnlyPID_EL_TimeCut->GetXaxis()->SetTitle("SigCors");
07364   hMeuOnlyPID_EL_TimeCut->GetXaxis()->CenterTitle();
07365   hMeuOnlyPID_EL_TimeCut->GetYaxis()->SetTitle("");
07366   hMeuOnlyPID_EL_TimeCut->GetYaxis()->CenterTitle();
07367   hMeuOnlyPID_EL_TimeCut->SetFillColor(0);
07368   hMeuOnlyPID_EL_TimeCut->SetBit(TH1::kCanRebin);
07369 
07370   TH1F *hMeuOnlyPID_EL_HppCut=new TH1F("hMeuOnlyPID_EL_HppCut",
07371                                    "hMeuOnlyPID_EL_HppCut",
07372                                    1000,-2,1000);
07373   hMeuOnlyPID_EL_HppCut->GetXaxis()->SetTitle("SigCors");
07374   hMeuOnlyPID_EL_HppCut->GetXaxis()->CenterTitle();
07375   hMeuOnlyPID_EL_HppCut->GetYaxis()->SetTitle("");
07376   hMeuOnlyPID_EL_HppCut->GetYaxis()->CenterTitle();
07377   hMeuOnlyPID_EL_HppCut->SetFillColor(0);
07378   hMeuOnlyPID_EL_HppCut->SetBit(TH1::kCanRebin);
07379 
07380   TH1F *hMeuNoPidCut=new TH1F("hMeuNoPidCut","hMeuNoPidCut",
07381                               1000,-2,1000);
07382   hMeuNoPidCut->GetXaxis()->SetTitle("SigCors");
07383   hMeuNoPidCut->GetXaxis()->CenterTitle();
07384   hMeuNoPidCut->GetYaxis()->SetTitle("");
07385   hMeuNoPidCut->GetYaxis()->CenterTitle();
07386   hMeuNoPidCut->SetFillColor(0);
07387   hMeuNoPidCut->SetBit(TH1::kCanRebin);
07388 
07389   TH1F *hMeuNoEventLengthCut=new TH1F("hMeuNoEventLengthCut",
07390                                       "hMeuNoEventLengthCut",
07391                                       1000,-2,1000);
07392   hMeuNoEventLengthCut->GetXaxis()->SetTitle("SigCors");
07393   hMeuNoEventLengthCut->GetXaxis()->CenterTitle();
07394   hMeuNoEventLengthCut->GetYaxis()->SetTitle("");
07395   hMeuNoEventLengthCut->GetYaxis()->CenterTitle();
07396   hMeuNoEventLengthCut->SetFillColor(0);
07397   hMeuNoEventLengthCut->SetBit(TH1::kCanRebin);
07398 
07399   TH1F *hMeuNoFidVolCut=new TH1F("hMeuNoFidVolCut","hMeuNoFidVolCut",
07400                                  1000,-2,1000);
07401   hMeuNoFidVolCut->GetXaxis()->SetTitle("SigCors");
07402   hMeuNoFidVolCut->GetXaxis()->CenterTitle();
07403   hMeuNoFidVolCut->GetYaxis()->SetTitle("");
07404   hMeuNoFidVolCut->GetYaxis()->CenterTitle();
07405   hMeuNoFidVolCut->SetFillColor(0);
07406   hMeuNoFidVolCut->SetBit(TH1::kCanRebin);
07407 
07408   TH1F *hMeuNoTrackQualityCut=new TH1F("hMeuNoTrackQualityCut",
07409                                        "hMeuNoTrackQualityCut",
07410                                        1000,-2,1000);
07411   hMeuNoTrackQualityCut->GetXaxis()->SetTitle("SigCors");
07412   hMeuNoTrackQualityCut->GetXaxis()->CenterTitle();
07413   hMeuNoTrackQualityCut->GetYaxis()->SetTitle("");
07414   hMeuNoTrackQualityCut->GetYaxis()->CenterTitle();
07415   hMeuNoTrackQualityCut->SetFillColor(0);
07416   hMeuNoTrackQualityCut->SetBit(TH1::kCanRebin);
07417 
07418   TH1F *hMeuNoPSMuCut=new TH1F("hMeuNoPSMuCut","hMeuNoPSMuCut",
07419                                1000,-2,1000);
07420   hMeuNoPSMuCut->GetXaxis()->SetTitle("SigCors");
07421   hMeuNoPSMuCut->GetXaxis()->CenterTitle();
07422   hMeuNoPSMuCut->GetYaxis()->SetTitle("");
07423   hMeuNoPSMuCut->GetYaxis()->CenterTitle();
07424   hMeuNoPSMuCut->SetFillColor(0);
07425   hMeuNoPSMuCut->SetBit(TH1::kCanRebin);
07426 
07427   TH1F *hMeuNoHitsPerPlaneCut=new TH1F("hMeuNoHitsPerPlaneCut",
07428                                        "hMeuNoHitsPerPlaneCut",
07429                                        1000,-2,1000);
07430   hMeuNoHitsPerPlaneCut->GetXaxis()->SetTitle("SigCors");
07431   hMeuNoHitsPerPlaneCut->GetXaxis()->CenterTitle();
07432   hMeuNoHitsPerPlaneCut->GetYaxis()->SetTitle("");
07433   hMeuNoHitsPerPlaneCut->GetYaxis()->CenterTitle();
07434   hMeuNoHitsPerPlaneCut->SetFillColor(0);
07435   hMeuNoHitsPerPlaneCut->SetBit(TH1::kCanRebin);
07436 
07437   TH1F *hMeuNoHitsPerPlane10Cut=new TH1F("hMeuNoHitsPerPlane10Cut",
07438                                          "hMeuNoHitsPerPlane10Cut",
07439                                          1000,-2,1000);
07440   hMeuNoHitsPerPlane10Cut->GetXaxis()->SetTitle("SigCors");
07441   hMeuNoHitsPerPlane10Cut->GetXaxis()->CenterTitle();
07442   hMeuNoHitsPerPlane10Cut->GetYaxis()->SetTitle("");
07443   hMeuNoHitsPerPlane10Cut->GetYaxis()->CenterTitle();
07444   hMeuNoHitsPerPlane10Cut->SetFillColor(0);
07445   hMeuNoHitsPerPlane10Cut->SetBit(TH1::kCanRebin);
07446 
07447   TH1F *h15_18=new TH1F("h15_18","h15_18",1000,-2,1000);
07448   h15_18->GetXaxis()->SetTitle("SigCors");
07449   h15_18->GetXaxis()->CenterTitle();
07450   h15_18->GetYaxis()->SetTitle("");
07451   h15_18->GetYaxis()->CenterTitle();
07452   h15_18->SetFillColor(0);
07453   h15_18->SetBit(TH1::kCanRebin);
07454 
07455   TH1F *h10_16=new TH1F("h10_16","h10_16",1000,-2,1000);
07456   h10_16->GetXaxis()->SetTitle("SigCors");
07457   h10_16->GetXaxis()->CenterTitle();
07458   h10_16->GetYaxis()->SetTitle("");
07459   h10_16->GetYaxis()->CenterTitle();
07460   h10_16->SetFillColor(0);
07461   h10_16->SetBit(TH1::kCanRebin);
07462 
07463   TH1F *h10_10=new TH1F("h10_10","h10_10",1000,-2,1000);
07464   h10_10->GetXaxis()->SetTitle("SigCors");
07465   h10_10->GetXaxis()->CenterTitle();
07466   h10_10->GetYaxis()->SetTitle("");
07467   h10_10->GetYaxis()->CenterTitle();
07468   h10_10->SetFillColor(0);
07469   h10_10->SetBit(TH1::kCanRebin);
07470 
07471   TH1F *h14_16=new TH1F("h14_16","h14_16",1000,-2,1000);
07472   h14_16->GetXaxis()->SetTitle("SigCors");
07473   h14_16->GetXaxis()->CenterTitle();
07474   h14_16->GetYaxis()->SetTitle("");
07475   h14_16->GetYaxis()->CenterTitle();
07476   h14_16->SetFillColor(0);
07477   h14_16->SetBit(TH1::kCanRebin);
07478 
07479   TH1F *h14_16OL=new TH1F("h14_16OL","h14_16OL",1000,-2,1000);
07480   h14_16OL->GetXaxis()->SetTitle("SigCors");
07481   h14_16OL->GetXaxis()->CenterTitle();
07482   h14_16OL->GetYaxis()->SetTitle("");
07483   h14_16OL->GetYaxis()->CenterTitle();
07484   h14_16OL->SetFillColor(0);
07485   h14_16OL->SetBit(TH1::kCanRebin);
07486 
07487   TH1F *h14_16NoTrkCut=new TH1F("h14_16NoTrkCut","h14_16NoTrkCut",
07488                                 1000,-2,1000);
07489   h14_16NoTrkCut->GetXaxis()->SetTitle("SigCors");
07490   h14_16NoTrkCut->GetXaxis()->CenterTitle();
07491   h14_16NoTrkCut->GetYaxis()->SetTitle("");
07492   h14_16NoTrkCut->GetYaxis()->CenterTitle();
07493   h14_16NoTrkCut->SetFillColor(0);
07494   h14_16NoTrkCut->SetBit(TH1::kCanRebin);
07495 
07496   TH1F *h14_16TrkUV=new TH1F("h14_16TrkUV","h14_16TrkUV",
07497                                 1000,-2,1000);
07498   h14_16TrkUV->GetXaxis()->SetTitle("SigCors");
07499   h14_16TrkUV->GetXaxis()->CenterTitle();
07500   h14_16TrkUV->GetYaxis()->SetTitle("");
07501   h14_16TrkUV->GetYaxis()->CenterTitle();
07502   h14_16TrkUV->SetFillColor(0);
07503   h14_16TrkUV->SetBit(TH1::kCanRebin);
07504 
07505   TH1F *h14_16NoXTalk=new TH1F("h14_16NoXTalk","h14_16NoXTalk",
07506                                1000,-2,1000);
07507   h14_16NoXTalk->GetXaxis()->SetTitle("SigCors");
07508   h14_16NoXTalk->GetXaxis()->CenterTitle();
07509   h14_16NoXTalk->GetYaxis()->SetTitle("");
07510   h14_16NoXTalk->GetYaxis()->CenterTitle();
07511   h14_16NoXTalk->SetFillColor(0);
07512   h14_16NoXTalk->SetBit(TH1::kCanRebin);
07513 
07514   TH1F *h14_16O1=new TH1F("h14_16O1","h14_16O1",1000,-2,1000);
07515   h14_16O1->GetXaxis()->SetTitle("SigCors");
07516   h14_16O1->GetXaxis()->CenterTitle();
07517   h14_16O1->GetYaxis()->SetTitle("");
07518   h14_16O1->GetYaxis()->CenterTitle();
07519   h14_16O1->SetFillColor(0);
07520   h14_16O1->SetBit(TH1::kCanRebin);
07521 
07522   TH1F *h14_16O2=new TH1F("h14_16O2","h14_16O2",1000,-2,1000);
07523   h14_16O2->GetXaxis()->SetTitle("SigCors");
07524   h14_16O2->GetXaxis()->CenterTitle();
07525   h14_16O2->GetYaxis()->SetTitle("");
07526   h14_16O2->GetYaxis()->CenterTitle();
07527   h14_16O2->SetFillColor(0);
07528   h14_16O2->SetBit(TH1::kCanRebin);
07529 
07530   TH1F *h14_16E1=new TH1F("h14_16E1","h14_16E1",1000,-2,1000);
07531   h14_16E1->GetXaxis()->SetTitle("SigCors");
07532   h14_16E1->GetXaxis()->CenterTitle();
07533   h14_16E1->GetYaxis()->SetTitle("");
07534   h14_16E1->GetYaxis()->CenterTitle();
07535   h14_16E1->SetFillColor(0);
07536   h14_16E1->SetBit(TH1::kCanRebin);
07537 
07538   TH1F *h14_16E2=new TH1F("h14_16E2","h14_16E2",1000,-2,1000);
07539   h14_16E2->GetXaxis()->SetTitle("SigCors");
07540   h14_16E2->GetXaxis()->CenterTitle();
07541   h14_16E2->GetYaxis()->SetTitle("");
07542   h14_16E2->GetYaxis()->CenterTitle();
07543   h14_16E2->SetFillColor(0);
07544   h14_16E2->SetBit(TH1::kCanRebin);
07545 
07546   TH1F *h14_16TimeCut=new TH1F("h14_16TimeCut","h14_16TimeCut",
07547                                1000,-2,1000);
07548   h14_16TimeCut->GetXaxis()->SetTitle("SigCors");
07549   h14_16TimeCut->GetXaxis()->CenterTitle();
07550   h14_16TimeCut->GetYaxis()->SetTitle("");
07551   h14_16TimeCut->GetYaxis()->CenterTitle();
07552   h14_16TimeCut->SetFillColor(0);
07553   h14_16TimeCut->SetBit(TH1::kCanRebin);
07554 
07555   TH1F *h14_16TimeCutO1=new TH1F("h14_16TimeCutO1","h14_16TimeCutO1",
07556                                  1000,-2,1000);
07557   h14_16TimeCutO1->GetXaxis()->SetTitle("SigCors");
07558   h14_16TimeCutO1->GetXaxis()->CenterTitle();
07559   h14_16TimeCutO1->GetYaxis()->SetTitle("");
07560   h14_16TimeCutO1->GetYaxis()->CenterTitle();
07561   h14_16TimeCutO1->SetFillColor(0);
07562   h14_16TimeCutO1->SetBit(TH1::kCanRebin);
07563 
07564   TH1F *h14_16TimeCutO2=new TH1F("h14_16TimeCutO2","h14_16TimeCutO2",
07565                                  1000,-2,1000);
07566   h14_16TimeCutO2->GetXaxis()->SetTitle("SigCors");
07567   h14_16TimeCutO2->GetXaxis()->CenterTitle();
07568   h14_16TimeCutO2->GetYaxis()->SetTitle("");
07569   h14_16TimeCutO2->GetYaxis()->CenterTitle();
07570   h14_16TimeCutO2->SetFillColor(0);
07571   h14_16TimeCutO2->SetBit(TH1::kCanRebin);
07572 
07573   TH1F *h14_16TimeCutE1=new TH1F("h14_16TimeCutE1","h14_16TimeCutE1",
07574                                  1000,-2,1000);
07575   h14_16TimeCutE1->GetXaxis()->SetTitle("SigCors");
07576   h14_16TimeCutE1->GetXaxis()->CenterTitle();
07577   h14_16TimeCutE1->GetYaxis()->SetTitle("");
07578   h14_16TimeCutE1->GetYaxis()->CenterTitle();
07579   h14_16TimeCutE1->SetFillColor(0);
07580   h14_16TimeCutE1->SetBit(TH1::kCanRebin);
07581 
07582   TH1F *h14_16TimeCutE2=new TH1F("h14_16TimeCutE2","h14_16TimeCutE2",
07583                                  1000,-2,1000);
07584   h14_16TimeCutE2->GetXaxis()->SetTitle("SigCors");
07585   h14_16TimeCutE2->GetXaxis()->CenterTitle();
07586   h14_16TimeCutE2->GetYaxis()->SetTitle("");
07587   h14_16TimeCutE2->GetYaxis()->CenterTitle();
07588   h14_16TimeCutE2->SetFillColor(0);
07589   h14_16TimeCutE2->SetBit(TH1::kCanRebin);
07590 
07591   TH1F *h14_16Straight=new TH1F("h14_16Straight","14_16Straight",
07592                                 1000,-2,1000);
07593   h14_16Straight->GetXaxis()->SetTitle("SigCors");
07594   h14_16Straight->GetXaxis()->CenterTitle();
07595   h14_16Straight->GetYaxis()->SetTitle("");
07596   h14_16Straight->GetYaxis()->CenterTitle();
07597   h14_16Straight->SetFillColor(0);
07598   h14_16Straight->SetBit(TH1::kCanRebin);
07599 
07600   TH1F *h14_10=new TH1F("h14_10","h14_10",1000,-2,1000);
07601   h14_10->GetXaxis()->SetTitle("SigCors");
07602   h14_10->GetXaxis()->CenterTitle();
07603   h14_10->GetYaxis()->SetTitle("");
07604   h14_10->GetYaxis()->CenterTitle();
07605   h14_10->SetFillColor(0);
07606   h14_10->SetBit(TH1::kCanRebin);
07607 
07608   TH1F *h18_16=new TH1F("h18_16","h18_16",1000,-2,1000);
07609   h18_16->GetXaxis()->SetTitle("SigCors");
07610   h18_16->GetXaxis()->CenterTitle();
07611   h18_16->GetYaxis()->SetTitle("");
07612   h18_16->GetYaxis()->CenterTitle();
07613   h18_16->SetFillColor(0);
07614   h18_16->SetBit(TH1::kCanRebin);
07615 
07616   TH1F *h18_10=new TH1F("h18_10","h18_10",1000,-2,1000);
07617   h18_10->GetXaxis()->SetTitle("SigCors");
07618   h18_10->GetXaxis()->CenterTitle();
07619   h18_10->GetYaxis()->SetTitle("");
07620   h18_10->GetYaxis()->CenterTitle();
07621   h18_10->SetFillColor(0);
07622   h18_10->SetBit(TH1::kCanRebin);
07623 
07624   TH1F *hEvLenFe=new TH1F("hEvLenFe","hEvLenFe",62,0,62);
07625   hEvLenFe->GetXaxis()->SetTitle("Event Length (Planes of Fe)");
07626   hEvLenFe->GetXaxis()->CenterTitle();
07627   hEvLenFe->GetYaxis()->SetTitle("");
07628   hEvLenFe->GetYaxis()->CenterTitle();
07629   hEvLenFe->SetFillColor(0);
07630   hEvLenFe->SetBit(TH1::kCanRebin);
07631 
07632   TH1F *hOLChi2=new TH1F("hOLChi2","hOLChi2",200,0,10);
07633   hOLChi2->GetXaxis()->SetTitle("OLChi2");
07634   hOLChi2->GetXaxis()->CenterTitle();
07635   hOLChi2->GetYaxis()->SetTitle("");
07636   hOLChi2->GetYaxis()->CenterTitle();
07637   hOLChi2->SetFillColor(0);
07638   hOLChi2->SetLineWidth(3);
07639   hOLChi2->SetLineColor(1);
07640   //hOLChi2->SetBit(TH1::kCanRebin);
07641 
07642   TH1F *hOLChi2N_1=new TH1F("hOLChi2N_1","hOLChi2N_1",200,0,10);
07643   hOLChi2N_1->GetXaxis()->SetTitle("OLChi2");
07644   hOLChi2N_1->GetXaxis()->CenterTitle();
07645   hOLChi2N_1->GetYaxis()->SetTitle("");
07646   hOLChi2N_1->GetYaxis()->CenterTitle();
07647   hOLChi2N_1->SetFillColor(0);
07648   hOLChi2N_1->SetLineWidth(3);
07649   hOLChi2N_1->SetLineColor(2);
07650   //hOLChi2N_1->SetBit(TH1::kCanRebin);
07651 
07652   TH1F *hOLChi2N=new TH1F("hOLChi2N","hOLChi2N",200,0,10);
07653   hOLChi2N->GetXaxis()->SetTitle("OLChi2");
07654   hOLChi2N->GetXaxis()->CenterTitle();
07655   hOLChi2N->GetYaxis()->SetTitle("");
07656   hOLChi2N->GetYaxis()->CenterTitle();
07657   hOLChi2N->SetFillColor(0);
07658   hOLChi2N->SetLineWidth(3);
07659   hOLChi2N->SetLineColor(4);
07660   //hOLChi2N->SetBit(TH1::kCanRebin);
07661 
07662   TProfile* pSigCorVsOLChi2Sum=new TProfile("pSigCorVsOLChi2Sum",
07663                                             "pSigCorVsOLChi2Sum",
07664                                             200,0,10);
07665 
07666   TProfile* pSigCorVsOLChi2=new TProfile("pSigCorVsOLChi2",
07667                                          "pSigCorVsOLChi2",200,0,10);
07668 
07669   TProfile* pSigCorVsRange=new TProfile("pSigCorVsRange",
07670                                         "pSigCorVsRange",62,0,62);
07671 
07672   //sum of all strip ends, normal and offset planes
07673   //tracked
07674   TProfile* pSigCorVsPlane=new TProfile("pSigCorVsPlane",
07675                                         "pSigCorVsPlane",
07676                                         62,0,62);
07677   TProfile* pSigCorVsOsPlane=new TProfile("pSigCorVsOsPlane",
07678                                           "pSigCorVsOsPlane",
07679                                           62,0,62);
07680 
07681   //xtalk + untracked hits
07682   TProfile* pSigCorVsPlaneX=new TProfile("pSigCorVsPlaneX",
07683                                          "pSigCorVsPlaneX",
07684                                          62,0,62);
07685   TProfile* pSigCorVsOsPlaneX=new TProfile("pSigCorVsOsPlaneX",
07686                                            "pSigCorVsOsPlaneX",
07687                                            62,0,62);
07688 
07689   //total
07690   TProfile* pSigCorVsPlaneT=new TProfile("pSigCorVsPlaneT",
07691                                          "pSigCorVsPlaneT",
07692                                          62,0,62);
07693   TProfile* pSigCorVsOsPlaneT=new TProfile("pSigCorVsOsPlaneT",
07694                                            "pSigCorVsOsPlaneT",
07695                                            62,0,62);
07696 
07697   //individual strip ends
07698   //tracked
07699   TProfile* pSigCorVsPlaneO1=new TProfile("pSigCorVsPlaneO1",
07700                                           "pSigCorVsPlaneO1",
07701                                           62,0,62);
07702   TProfile* pSigCorVsPlaneO2=new TProfile("pSigCorVsPlaneO2",
07703                                           "pSigCorVsPlaneO2",
07704                                           62,0,62);
07705   TProfile* pSigCorVsPlaneE1=new TProfile("pSigCorVsPlaneE1",
07706                                           "pSigCorVsPlaneE1",
07707                                           62,0,62);
07708   TProfile* pSigCorVsPlaneE2=new TProfile("pSigCorVsPlaneE2",
07709                                           "pSigCorVsPlaneE2",
07710                                           62,0,62);
07711   //xtalk + untracked hits
07712   TProfile* pSigCorVsPlaneO1X=new TProfile("pSigCorVsPlaneO1X",
07713                                           "pSigCorVsPlaneO1X",
07714                                           62,0,62);
07715   TProfile* pSigCorVsPlaneO2X=new TProfile("pSigCorVsPlaneO2X",
07716                                           "pSigCorVsPlaneO2X",
07717                                           62,0,62);
07718   TProfile* pSigCorVsPlaneE1X=new TProfile("pSigCorVsPlaneE1X",
07719                                           "pSigCorVsPlaneE1X",
07720                                           62,0,62);
07721   TProfile* pSigCorVsPlaneE2X=new TProfile("pSigCorVsPlaneE2X",
07722                                           "pSigCorVsPlaneE2X",
07723                                           62,0,62);
07724   //total
07725   TProfile* pSigCorVsPlaneO1T=new TProfile("pSigCorVsPlaneO1T",
07726                                           "pSigCorVsPlaneO1T",
07727                                           62,0,62);
07728   TProfile* pSigCorVsPlaneO2T=new TProfile("pSigCorVsPlaneO2T",
07729                                           "pSigCorVsPlaneO2T",
07730                                           62,0,62);
07731   TProfile* pSigCorVsPlaneE1T=new TProfile("pSigCorVsPlaneE1T",
07732                                           "pSigCorVsPlaneE1T",
07733                                           62,0,62);
07734   TProfile* pSigCorVsPlaneE2T=new TProfile("pSigCorVsPlaneE2T",
07735                                           "pSigCorVsPlaneE2T",
07736                                           62,0,62);
07737 
07738   //individual strip ends - offset planes
07739   //tracked
07740   TProfile* pSigCorVsOsPlaneO1=new TProfile("pSigCorVsOsPlaneO1",
07741                                             "pSigCorVsOsPlaneO1",
07742                                             62,0,62);
07743   TProfile* pSigCorVsOsPlaneO2=new TProfile("pSigCorVsOsPlaneO2",
07744                                             "pSigCorVsOsPlaneO2",
07745                                             62,0,62);
07746   TProfile* pSigCorVsOsPlaneE1=new TProfile("pSigCorVsOsPlaneE1",
07747                                             "pSigCorVsOsPlaneE1",
07748                                             62,0,62);
07749   TProfile* pSigCorVsOsPlaneE2=new TProfile("pSigCorVsOsPlaneE2",
07750                                             "pSigCorVsOsPlaneE2",
07751                                             62,0,62);
07752 
07753   //xtalk + untracked hits
07754   TProfile* pSigCorVsOsPlaneO1X=new TProfile("pSigCorVsOsPlaneO1X",
07755                                              "pSigCorVsOsPlaneO1X",
07756                                              62,0,62);
07757   TProfile* pSigCorVsOsPlaneO2X=new TProfile("pSigCorVsOsPlaneO2X",
07758                                             "pSigCorVsOsPlaneO2X",
07759                                             62,0,62);
07760   TProfile* pSigCorVsOsPlaneE1X=new TProfile("pSigCorVsOsPlaneE1X",
07761                                             "pSigCorVsOsPlaneE1X",
07762                                             62,0,62);
07763   TProfile* pSigCorVsOsPlaneE2X=new TProfile("pSigCorVsOsPlaneE2X",
07764                                             "pSigCorVsOsPlaneE2X",
07765                                             62,0,62);
07766   //total
07767   TProfile* pSigCorVsOsPlaneO1T=new TProfile("pSigCorVsOsPlaneO1T",
07768                                             "pSigCorVsOsPlaneO1T",
07769                                             62,0,62);
07770   TProfile* pSigCorVsOsPlaneO2T=new TProfile("pSigCorVsOsPlaneO2T",
07771                                             "pSigCorVsOsPlaneO2T",
07772                                             62,0,62);
07773   TProfile* pSigCorVsOsPlaneE1T=new TProfile("pSigCorVsOsPlaneE1T",
07774                                             "pSigCorVsOsPlaneE1T",
07775                                             62,0,62);
07776   TProfile* pSigCorVsOsPlaneE2T=new TProfile("pSigCorVsOsPlaneE2T",
07777                                             "pSigCorVsOsPlaneE2T",
07778                                             62,0,62);
07779 
07780   TProfile* pMeuVsHit_PlCut=new TProfile("pMeuVsHit_PlCut",
07781                                          "pMeuVsHit_PlCut",120,0,12);
07782   pMeuVsHit_PlCut->SetTitle("MEU vs Hits/Plane Cut");
07783   pMeuVsHit_PlCut->GetXaxis()->SetTitle("Hits/Plane Cut");
07784   pMeuVsHit_PlCut->GetXaxis()->CenterTitle();
07785   pMeuVsHit_PlCut->GetYaxis()->SetTitle("SigCors per MEU");
07786   pMeuVsHit_PlCut->GetYaxis()->CenterTitle();
07787   pMeuVsHit_PlCut->SetFillColor(0);
07788 
07789   TProfile* pMeuVsHit_PlCut10=new TProfile("pMeuVsHit_PlCut10",
07790                                            "pMeuVsHit_PlCut10",
07791                                            120,0,12);
07792   pMeuVsHit_PlCut10->SetTitle("MEU vs Hits/Plane Cut");
07793   pMeuVsHit_PlCut10->GetXaxis()->SetTitle("Hits/Plane Cut");
07794   pMeuVsHit_PlCut10->GetXaxis()->CenterTitle();
07795   pMeuVsHit_PlCut10->GetYaxis()->SetTitle("SigCors per MEU");
07796   pMeuVsHit_PlCut10->GetYaxis()->CenterTitle();
07797   pMeuVsHit_PlCut10->SetFillColor(0);
07798 
07799   TProfile* pMeuVsLowTimeCutN_1=new TProfile("pMeuVsLowTimeCutN_1",
07800                                              "pMeuVsLowTimeCutN_1",
07801                                              50,-500,500);
07802   pMeuVsLowTimeCutN_1->SetTitle("MEU vs Time Cut");
07803   pMeuVsLowTimeCutN_1->GetXaxis()->SetTitle("Time Cut");
07804   pMeuVsLowTimeCutN_1->GetXaxis()->CenterTitle();
07805   pMeuVsLowTimeCutN_1->GetYaxis()->SetTitle("SigCors per MEU");
07806   pMeuVsLowTimeCutN_1->GetYaxis()->CenterTitle();
07807   pMeuVsLowTimeCutN_1->SetFillColor(0);
07808   pMeuVsLowTimeCutN_1->SetLineColor(2);
07809 
07810   TProfile* pMeuVsLowTimeCutN=new TProfile("pMeuVsLowTimeCutN",
07811                                            "pMeuVsLowTimeCutN",
07812                                            50,-500,500);
07813   pMeuVsLowTimeCutN->SetTitle("MEU vs Time Cut");
07814   pMeuVsLowTimeCutN->GetXaxis()->SetTitle("Time Cut");
07815   pMeuVsLowTimeCutN->GetXaxis()->CenterTitle();
07816   pMeuVsLowTimeCutN->GetYaxis()->SetTitle("SigCors per MEU");
07817   pMeuVsLowTimeCutN->GetYaxis()->CenterTitle();
07818   pMeuVsLowTimeCutN->SetFillColor(0);
07819   pMeuVsLowTimeCutN->SetLineColor(4);
07820 
07821   TProfile* pMeuVsUpTimeCutN_1=new TProfile("pMeuVsUpTimeCutN_1",
07822                                             "pMeuVsUpTimeCutN_1",
07823                                             50,-500,500);
07824   pMeuVsUpTimeCutN_1->SetTitle("MEU vs Time Cut");
07825   pMeuVsUpTimeCutN_1->GetXaxis()->SetTitle("Time Cut");
07826   pMeuVsUpTimeCutN_1->GetXaxis()->CenterTitle();
07827   pMeuVsUpTimeCutN_1->GetYaxis()->SetTitle("SigCors per MEU");
07828   pMeuVsUpTimeCutN_1->GetYaxis()->CenterTitle();
07829   pMeuVsUpTimeCutN_1->SetFillColor(0);
07830   pMeuVsUpTimeCutN_1->SetLineColor(2);
07831 
07832   TProfile* pMeuVsUpTimeCutN=new TProfile("pMeuVsUpTimeCutN",
07833                                           "pMeuVsUpTimeCutN",
07834                                           50,-500,500);
07835   pMeuVsUpTimeCutN->SetTitle("MEU vs Time Cut");
07836   pMeuVsUpTimeCutN->GetXaxis()->SetTitle("Time Cut");
07837   pMeuVsUpTimeCutN->GetXaxis()->CenterTitle();
07838   pMeuVsUpTimeCutN->GetYaxis()->SetTitle("SigCors per MEU");
07839   pMeuVsUpTimeCutN->GetYaxis()->CenterTitle();
07840   pMeuVsUpTimeCutN->SetFillColor(0);
07841   pMeuVsUpTimeCutN->SetLineColor(4);
07842 
07843   TProfile* pMeuVsLowEvLenCutN=new TProfile("pMeuVsLowEvLenCutN",
07844                                         "pMeuVsLowEvLenCutN",62,0,62);
07845   pMeuVsLowEvLenCutN->SetTitle("MEU vs Event Length Cut");
07846   pMeuVsLowEvLenCutN->GetXaxis()->SetTitle("Lower Event Length Cut");
07847   pMeuVsLowEvLenCutN->GetXaxis()->CenterTitle();
07848   pMeuVsLowEvLenCutN->GetYaxis()->SetTitle("SigCors per MEU");
07849   pMeuVsLowEvLenCutN->GetYaxis()->CenterTitle();
07850   pMeuVsLowEvLenCutN->SetFillColor(0);
07851 
07852   TProfile* pMeuVsLowEvLenCutNormN=new TProfile
07853     ("pMeuVsLowEvLenCutNormN","pMeuVsLowEvLenCutNormN",62,0,62);
07854   pMeuVsLowEvLenCutNormN->SetTitle("Normalised MEU vs Event Length Cut");
07855   pMeuVsLowEvLenCutNormN->GetXaxis()->SetTitle("Lower Event Length Cut");
07856   pMeuVsLowEvLenCutNormN->GetXaxis()->CenterTitle();
07857   pMeuVsLowEvLenCutNormN->GetYaxis()->SetTitle("Normalised SigCors/MEU");
07858   pMeuVsLowEvLenCutNormN->GetYaxis()->CenterTitle();
07859   pMeuVsLowEvLenCutNormN->SetFillColor(0);
07860 
07861   TProfile* pMeuVsLowEvLenCutN_1=new TProfile
07862     ("pMeuVsLowEvLenCutN_1","pMeuVsLowEvLenCutN_1",62,0,62);
07863   pMeuVsLowEvLenCutN_1->SetTitle("MEU vs Event Length Cut");
07864   pMeuVsLowEvLenCutN_1->GetXaxis()->SetTitle("Lower Event Length Cut");
07865   pMeuVsLowEvLenCutN_1->GetXaxis()->CenterTitle();
07866   pMeuVsLowEvLenCutN_1->GetYaxis()->SetTitle("SigCors per MEU");
07867   pMeuVsLowEvLenCutN_1->GetYaxis()->CenterTitle();
07868   pMeuVsLowEvLenCutN_1->SetFillColor(0);
07869 
07870   TProfile* pMeuVsLowEvLenCutNormN_1=new TProfile
07871     ("pMeuVsLowEvLenCutNormN_1","pMeuVsLowEvLenCutNormN_1",62,0,62);
07872   pMeuVsLowEvLenCutNormN_1->SetTitle
07873     ("Normalised MEU vs Event Length Cut");
07874   pMeuVsLowEvLenCutNormN_1->GetXaxis()->SetTitle
07875     ("Lower Event Length Cut");
07876   pMeuVsLowEvLenCutNormN_1->GetXaxis()->CenterTitle();
07877   pMeuVsLowEvLenCutNormN_1->GetYaxis()->SetTitle
07878     ("Normalised SigCors/MEU");
07879   pMeuVsLowEvLenCutNormN_1->GetYaxis()->CenterTitle();
07880   pMeuVsLowEvLenCutNormN_1->SetFillColor(0);
07881 
07882   TProfile* pMeuVsUpEvLenCutN=new TProfile("pMeuVsUpEvLenCutN",
07883                                         "pMeuVsUpEvLenCutN",62,0,62);
07884   pMeuVsUpEvLenCutN->SetTitle("MEU vs Event Length Cut");
07885   pMeuVsUpEvLenCutN->GetXaxis()->SetTitle("Lower Event Length Cut");
07886   pMeuVsUpEvLenCutN->GetXaxis()->CenterTitle();
07887   pMeuVsUpEvLenCutN->GetYaxis()->SetTitle("SigCors per MEU");
07888   pMeuVsUpEvLenCutN->GetYaxis()->CenterTitle();
07889   pMeuVsUpEvLenCutN->SetFillColor(0);
07890 
07891   TProfile* pMeuVsUpEvLenCutNormN=new TProfile("pMeuVsUpEvLenCutNormN",
07892                                         "pMeuVsUpEvLenCutNormN",62,0,62);
07893   pMeuVsUpEvLenCutNormN->SetTitle("Normalised MEU vs Event Length Cut");
07894   pMeuVsUpEvLenCutNormN->GetXaxis()->SetTitle("Lower Event Length Cut");
07895   pMeuVsUpEvLenCutNormN->GetXaxis()->CenterTitle();
07896   pMeuVsUpEvLenCutNormN->GetYaxis()->SetTitle("Normalised SigCors/MEU");
07897   pMeuVsUpEvLenCutNormN->GetYaxis()->CenterTitle();
07898   pMeuVsUpEvLenCutNormN->SetFillColor(0);
07899 
07900   TProfile* pMeuVsUpEvLenCutN_1=new TProfile("pMeuVsUpEvLenCutN_1",
07901                                         "pMeuVsUpEvLenCutN_1",62,0,62);
07902   pMeuVsUpEvLenCutN_1->SetTitle("MEU vs Event Length Cut");
07903   pMeuVsUpEvLenCutN_1->GetXaxis()->SetTitle("Lower Event Length Cut");
07904   pMeuVsUpEvLenCutN_1->GetXaxis()->CenterTitle();
07905   pMeuVsUpEvLenCutN_1->GetYaxis()->SetTitle("SigCors per MEU");
07906   pMeuVsUpEvLenCutN_1->GetYaxis()->CenterTitle();
07907   pMeuVsUpEvLenCutN_1->SetFillColor(0);
07908 
07909   TProfile* pMeuVsUpEvLenCutNormN_1=new TProfile
07910     ("pMeuVsUpEvLenCutNormN_1","pMeuVsUpEvLenCutNormN_1",62,0,62);
07911   pMeuVsUpEvLenCutNormN_1->SetTitle
07912     ("Normalised MEU vs Event Length Cut");
07913   pMeuVsUpEvLenCutNormN_1->GetXaxis()->SetTitle
07914     ("Lower Event Length Cut");
07915   pMeuVsUpEvLenCutNormN_1->GetXaxis()->CenterTitle();
07916   pMeuVsUpEvLenCutNormN_1->GetYaxis()->SetTitle
07917     ("Normalised SigCors/MEU");
07918   pMeuVsUpEvLenCutNormN_1->GetYaxis()->CenterTitle();
07919   pMeuVsUpEvLenCutNormN_1->SetFillColor(0);
07920 
07921   TProfile* pMeuVsStraightness=new TProfile("pMeuVsStraightness",
07922                                             "pMeuVsStraightness",
07923                                             100,-0.025,0.6);
07924   pMeuVsStraightness->SetTitle("MEU Vs TrackStraightness");
07925   pMeuVsStraightness->GetXaxis()->
07926     SetTitle("Straightness Radius Cut (m from centre)");
07927   pMeuVsStraightness->GetXaxis()->CenterTitle();
07928   pMeuVsStraightness->GetYaxis()->SetTitle("MEU");
07929   pMeuVsStraightness->GetYaxis()->CenterTitle();
07930   pMeuVsStraightness->SetFillColor(0);
07931 
07932   TProfile* pMeuVsStraightnessN=new TProfile("pMeuVsStraightnessN",
07933                                              "pMeuVsStraightnessN",
07934                                              100,-0.025,0.6);
07935   pMeuVsStraightnessN->SetTitle("Normalised MEU Vs TrackStraightness");
07936   pMeuVsStraightnessN->GetXaxis()->
07937     SetTitle("Straightness Radius Cut (m from centre)");
07938   pMeuVsStraightnessN->GetXaxis()->CenterTitle();
07939   pMeuVsStraightnessN->GetYaxis()->SetTitle("Normalised MEU");
07940   pMeuVsStraightnessN->GetYaxis()->CenterTitle();
07941   pMeuVsStraightnessN->SetFillColor(0);
07942 
07943   TH1F *hStripsFromCentre=new TH1F("hStripsFromCentre",
07944                                    "hStripsFromCentre",12,0,12);
07945   hStripsFromCentre->GetXaxis()->SetTitle("Strips from Centre");
07946   hStripsFromCentre->GetXaxis()->CenterTitle();
07947   hStripsFromCentre->GetYaxis()->SetTitle("");
07948   hStripsFromCentre->GetYaxis()->CenterTitle();
07949   hStripsFromCentre->SetFillColor(0);
07950   //hStripsFromCentre->SetBit(TH1::kCanRebin);
07951 
07952   TH1F *hStripsFromCentrePeCut=new TH1F("hStripsFromCentrePeCut",
07953                                         "hStripsFromCentrePeCut",
07954                                         14,0,14);
07955   hStripsFromCentrePeCut->GetXaxis()->SetTitle("Strips from Centre");
07956   hStripsFromCentrePeCut->GetXaxis()->CenterTitle();
07957   hStripsFromCentrePeCut->GetYaxis()->SetTitle("");
07958   hStripsFromCentrePeCut->GetYaxis()->CenterTitle();
07959   hStripsFromCentrePeCut->SetFillColor(0);
07960   //hStripsFromCentrePeCut->SetBit(TH1::kCanRebin);
07961 
07962   TH1F *hStripsFromCentrePeCutN_1=new TH1F("hStripsFromCentrePeCutN_1",
07963                                         "hStripsFromCentrePeCutN_1",
07964                                         14,0,14);
07965   hStripsFromCentrePeCutN_1->GetXaxis()->SetTitle("Strips from Centre");
07966   hStripsFromCentrePeCutN_1->GetXaxis()->CenterTitle();
07967   hStripsFromCentrePeCutN_1->GetYaxis()->SetTitle("");
07968   hStripsFromCentrePeCutN_1->GetYaxis()->CenterTitle();
07969   hStripsFromCentrePeCutN_1->SetFillColor(0);
07970   hStripsFromCentrePeCutN_1->SetLineColor(2);
07971   //hStripsFromCentrePeCutN_1->SetBit(TH1::kCanRebin);
07972 
07973   TH1F *hStripsFromCentrePeCutN=new TH1F("hStripsFromCentrePeCutN",
07974                                         "hStripsFromCentrePeCutN",
07975                                         14,0,14);
07976   hStripsFromCentrePeCutN->GetXaxis()->SetTitle("Strips from Centre");
07977   hStripsFromCentrePeCutN->GetXaxis()->CenterTitle();
07978   hStripsFromCentrePeCutN->GetYaxis()->SetTitle("");
07979   hStripsFromCentrePeCutN->GetYaxis()->CenterTitle();
07980   hStripsFromCentrePeCutN->SetFillColor(0);
07981   hStripsFromCentrePeCutN->SetLineColor(4);
07982   //hStripsFromCentrePeCutN->SetBit(TH1::kCanRebin);
07983 
07984   TProfile* pMeuVsStripCut=new TProfile("pMeuVsStripCut",
07985                                         "pMeuVsStripCut",
07986                                         12,0,12);
07987   pMeuVsStripCut->SetTitle("MEU Vs Strips from Centre");
07988   pMeuVsStripCut->GetXaxis()->
07989     SetTitle("Strip Cut (strips from centre)");
07990   pMeuVsStripCut->GetXaxis()->CenterTitle();
07991   pMeuVsStripCut->GetYaxis()->SetTitle("MEU");
07992   pMeuVsStripCut->GetYaxis()->CenterTitle();
07993   pMeuVsStripCut->SetFillColor(0);
07994 
07995   TProfile* pMeuVsStripCutPeCut=new TProfile("pMeuVsStripCutPeCut",
07996                                              "pMeuVsStripCutPeCut",
07997                                              14,0,14);
07998   pMeuVsStripCutPeCut->SetTitle("MEU Vs Strips from Centre (PeCut)");
07999   pMeuVsStripCutPeCut->GetXaxis()->
08000     SetTitle("Strip Cut (strips from centre)");
08001   pMeuVsStripCutPeCut->GetXaxis()->CenterTitle();
08002   pMeuVsStripCutPeCut->GetYaxis()->SetTitle("MEU");
08003   pMeuVsStripCutPeCut->GetYaxis()->CenterTitle();
08004   pMeuVsStripCutPeCut->SetFillColor(0);
08005 
08006   fS="Strip Vs Plane: Av. SigCor in Track Window";
08007   TProfile2D* pStVsPlWin=new TProfile2D("pStVsPlWin",fS.c_str(),
08008                                       64,-2,62,30,-3,27);
08009   pStVsPlWin->GetXaxis()->SetTitle("Plane");
08010   pStVsPlWin->GetXaxis()->CenterTitle();
08011   pStVsPlWin->GetYaxis()->SetTitle("Strip");
08012   pStVsPlWin->GetYaxis()->CenterTitle();
08013   pStVsPlWin->SetFillColor(0);
08014   //pStVsPlWin->SetMaximum(15000);
08015 
08016   fS="Av. Fraction of MEU";
08017   TProfile2D* pStVsPlWinFract=new TProfile2D("pStVsPlWinFract",
08018                                              fS.c_str(),
08019                                              64,-2,62,30,-3,27);
08020   pStVsPlWinFract->GetXaxis()->SetTitle("Plane");
08021   pStVsPlWinFract->GetXaxis()->CenterTitle();
08022   pStVsPlWinFract->GetYaxis()->SetTitle("Strip");
08023   pStVsPlWinFract->GetYaxis()->CenterTitle();
08024   pStVsPlWinFract->SetFillColor(0);
08025   //pStVsPlWinFract->SetMaximum(15000);
08026 
08027   fS="Strip Vs Plane: Number of Hits in Track Window";
08028   TH2F* hStVsPlNum=new TH2F("hStVsPlNum",fS.c_str(),
08029                           64,-2,62,30,-3,27);
08030   hStVsPlNum->GetXaxis()->SetTitle("Plane");
08031   hStVsPlNum->GetXaxis()->CenterTitle();
08032   hStVsPlNum->GetYaxis()->SetTitle("Strip");
08033   hStVsPlNum->GetYaxis()->CenterTitle();
08034   hStVsPlNum->SetFillColor(0);
08035   //hStVsPlNum->SetMaximum(15000);
08036 
08037 
08038   fS="Strip Vs Plane SigCor (SE1)";
08039   TProfile2D* pStVsPl1=new TProfile2D("pStVsPl1",fS.c_str(),
08040                                       64,-2,62,30,-3,27);
08041   pStVsPl1->GetXaxis()->SetTitle("Plane");
08042   pStVsPl1->GetXaxis()->CenterTitle();
08043   pStVsPl1->GetYaxis()->SetTitle("Strip");
08044   pStVsPl1->GetYaxis()->CenterTitle();
08045   pStVsPl1->SetFillColor(0);
08046   //pStVsPl1->SetMaximum(15000);
08047 
08048   fS="Strip Vs Plane SigCor (SE2)";
08049   TProfile2D* pStVsPl2=new TProfile2D("pStVsPl2",fS.c_str(),
08050                                       64,-2,62,30,-3,27);
08051   pStVsPl2->GetXaxis()->SetTitle("Plane");
08052   pStVsPl2->GetXaxis()->CenterTitle();
08053   pStVsPl2->GetYaxis()->SetTitle("Strip");
08054   pStVsPl2->GetYaxis()->CenterTitle();
08055   pStVsPl2->SetFillColor(0);
08056   //pStVsPl2->SetMaximum(15000);
08057 
08058   fS="Strip Vs Plane SigCor (SE1)";
08059   TH2F* hStVsPl1=new TH2F("hStVsPl1",fS.c_str(),
08060                           64,-2,62,30,-3,27);
08061   hStVsPl1->GetXaxis()->SetTitle("Plane");
08062   hStVsPl1->GetXaxis()->CenterTitle();
08063   hStVsPl1->GetYaxis()->SetTitle("Strip");
08064   hStVsPl1->GetYaxis()->CenterTitle();
08065   hStVsPl1->SetFillColor(0);
08066   //hStVsPl1->SetMaximum(15000);
08067 
08068   fS="Strip Vs Plane SigCor (SE2)";
08069   TH2F* hStVsPl2=new TH2F("hStVsPl2",fS.c_str(),
08070                                       64,-2,62,30,-3,27);
08071   hStVsPl2->GetXaxis()->SetTitle("Plane");
08072   hStVsPl2->GetXaxis()->CenterTitle();
08073   hStVsPl2->GetYaxis()->SetTitle("Strip");
08074   hStVsPl2->GetYaxis()->CenterTitle();
08075   hStVsPl2->SetFillColor(0);
08076   //hStVsPl2->SetMaximum(15000);
08077 
08078   TH1F *hNumPlanesMuPi=new TH1F("hNumPlanesMuPi","hNumPlanesMuPi",
08079                                 77,-2,75);
08080   hNumPlanesMuPi->SetTitle("Number of Planes Hit");
08081   hNumPlanesMuPi->GetXaxis()->SetTitle("Number of Planes Hit");
08082   hNumPlanesMuPi->GetXaxis()->CenterTitle();
08083   hNumPlanesMuPi->GetYaxis()->SetTitle("");
08084   hNumPlanesMuPi->GetYaxis()->CenterTitle();
08085   hNumPlanesMuPi->SetFillColor(0);
08086   hNumPlanesMuPi->SetBit(TH1::kCanRebin);
08087 
08088   TH1F *hNumPlanes=new TH1F("hNumPlanes","hNumPlanes",77,-2,75);
08089   hNumPlanes->SetTitle("Number of Planes Hit");
08090   hNumPlanes->GetXaxis()->SetTitle("Number of Planes Hit");
08091   hNumPlanes->GetXaxis()->CenterTitle();
08092   hNumPlanes->GetYaxis()->SetTitle("");
08093   hNumPlanes->GetYaxis()->CenterTitle();
08094   hNumPlanes->SetFillColor(0);
08095   hNumPlanes->SetBit(TH1::kCanRebin);
08096 
08097   TH1F *hNumPlanesN_1=new TH1F("hNumPlanesN_1","hNumPlanesN_1",
08098                                77,-2,75);
08099   hNumPlanesN_1->SetTitle("Number of Planes Hit");  
08100   hNumPlanesN_1->GetXaxis()->SetTitle("Number of Planes Hit");
08101   hNumPlanesN_1->GetXaxis()->CenterTitle();
08102   hNumPlanesN_1->GetYaxis()->SetTitle("");
08103   hNumPlanesN_1->GetYaxis()->CenterTitle();
08104   hNumPlanesN_1->SetFillColor(0);
08105   hNumPlanesN_1->SetLineColor(2);
08106   hNumPlanesN_1->SetBit(TH1::kCanRebin);
08107 
08108   TH1F *hNumPlanesN=new TH1F("hNumPlanesN","hNumPlanesN",
08109                                77,-2,75);
08110   hNumPlanesN->SetTitle("Number of Planes Hit");  
08111   hNumPlanesN->GetXaxis()->SetTitle("Number of Planes Hit");
08112   hNumPlanesN->GetXaxis()->CenterTitle();
08113   hNumPlanesN->GetYaxis()->SetTitle("");
08114   hNumPlanesN->GetYaxis()->CenterTitle();
08115   hNumPlanesN->SetFillColor(0);
08116   hNumPlanesN->SetLineColor(4);
08117   hNumPlanesN->SetBit(TH1::kCanRebin);
08118 
08119   TH1F *hEventLength=new TH1F("hEventLength","hEventLength",77,-2,75);
08120   hEventLength->SetTitle("Event Length");
08121   hEventLength->GetXaxis()->SetTitle("Event Length");
08122   hEventLength->GetXaxis()->CenterTitle();
08123   hEventLength->GetYaxis()->SetTitle("");
08124   hEventLength->GetYaxis()->CenterTitle();
08125   hEventLength->SetFillColor(0);
08126   hEventLength->SetBit(TH1::kCanRebin);
08127 
08128   TH1F *hEventLengthN_1=new TH1F("hEventLengthN_1","hEventLengthN_1",
08129                                77,-2,75);
08130   hEventLengthN_1->SetTitle("Event Length");  
08131   hEventLengthN_1->GetXaxis()->SetTitle("Event Length");
08132   hEventLengthN_1->GetXaxis()->CenterTitle();
08133   hEventLengthN_1->GetYaxis()->SetTitle("");
08134   hEventLengthN_1->GetYaxis()->CenterTitle();
08135   hEventLengthN_1->SetFillColor(0);
08136   hEventLengthN_1->SetLineColor(2);
08137   hEventLengthN_1->SetBit(TH1::kCanRebin);
08138 
08139   TH1F *hEventLengthN=new TH1F("hEventLengthN","hEventLengthN",
08140                                77,-2,75);
08141   hEventLengthN->SetTitle("Event Length");  
08142   hEventLengthN->GetXaxis()->SetTitle("Event Length");
08143   hEventLengthN->GetXaxis()->CenterTitle();
08144   hEventLengthN->GetYaxis()->SetTitle("");
08145   hEventLengthN->GetYaxis()->CenterTitle();
08146   hEventLengthN->SetFillColor(0);
08147   hEventLengthN->SetLineColor(4);
08148   hEventLengthN->SetBit(TH1::kCanRebin);
08149 
08150   TH1F *hNumHits=new TH1F("hNumHits","hNumHits",200,-2,200);
08151   hNumHits->SetTitle("Number of Hits");
08152   hNumHits->GetXaxis()->SetTitle("Number of Hits");
08153   hNumHits->GetXaxis()->CenterTitle();
08154   hNumHits->GetYaxis()->SetTitle("");
08155   hNumHits->GetYaxis()->CenterTitle();
08156   hNumHits->SetFillColor(0);
08157   //hNumHits->SetBit(TH1::kCanRebin);
08158 
08159   TH1F *hNumHitsN_1=new TH1F("hNumHitsN_1","hNumHitsN_1",200,-2,200);
08160   hNumHitsN_1->SetTitle("Number of Hits");
08161   hNumHitsN_1->GetXaxis()->SetTitle("Number of Hits");
08162   hNumHitsN_1->GetXaxis()->CenterTitle();
08163   hNumHitsN_1->GetYaxis()->SetTitle("");
08164   hNumHitsN_1->GetYaxis()->CenterTitle();
08165   hNumHitsN_1->SetFillColor(0);
08166   hNumHitsN_1->SetLineColor(2);
08167   //hNumHitsN_1->SetBit(TH1::kCanRebin);
08168 
08169   TH1F *hNumHitsN=new TH1F("hNumHitsN","hNumHitsN",200,-2,200);
08170   hNumHitsN->SetTitle("Number of Hits");
08171   hNumHitsN->GetXaxis()->SetTitle("Number of Hits");
08172   hNumHitsN->GetXaxis()->CenterTitle();
08173   hNumHitsN->GetYaxis()->SetTitle("");
08174   hNumHitsN->GetYaxis()->CenterTitle();
08175   hNumHitsN->SetFillColor(0);
08176   hNumHitsN->SetLineColor(4);
08177   //hNumHitsN->SetBit(TH1::kCanRebin);
08178 
08179   TH1F *hHitsPerPl=new TH1F("hHitsPerPl","hHitsPerPl",
08180                                200,-1,12);
08181   hHitsPerPl->SetTitle("Number of Hits per Plane");
08182   hHitsPerPl->GetXaxis()->SetTitle("Number of Hits per Plane");
08183   hHitsPerPl->GetXaxis()->CenterTitle();
08184   hHitsPerPl->GetYaxis()->SetTitle("");
08185   hHitsPerPl->GetYaxis()->CenterTitle();
08186   hHitsPerPl->SetFillColor(0);
08187   //hHitsPerPl->SetBit(TH1::kCanRebin);
08188 
08189   TH1F *hHitsPerPlN_1=new TH1F("hHitsPerPlN_1","hHitsPerPlN_1",
08190                                200,-1,12);
08191   hHitsPerPlN_1->SetTitle("Number of Hits per Plane");
08192   hHitsPerPlN_1->GetXaxis()->SetTitle("Number of Hits per Plane");
08193   hHitsPerPlN_1->GetXaxis()->CenterTitle();
08194   hHitsPerPlN_1->GetYaxis()->SetTitle("");
08195   hHitsPerPlN_1->GetYaxis()->CenterTitle();
08196   hHitsPerPlN_1->SetFillColor(0);
08197   hHitsPerPlN_1->SetLineColor(2);
08198   //hHitsPerPlN_1->SetBit(TH1::kCanRebin);
08199 
08200   TH1F *hHitsPerPlN_1XCut=new TH1F("hHitsPerPlN_1XCut",
08201                                    "hHitsPerPlN_1XCut",
08202                                    200,-1,12);
08203   hHitsPerPlN_1XCut->SetTitle("Number of Hits per Plane");
08204   hHitsPerPlN_1XCut->GetXaxis()->SetTitle("Number of Hits per Plane");
08205   hHitsPerPlN_1XCut->GetXaxis()->CenterTitle();
08206   hHitsPerPlN_1XCut->GetYaxis()->SetTitle("");
08207   hHitsPerPlN_1XCut->GetYaxis()->CenterTitle();
08208   hHitsPerPlN_1XCut->SetFillColor(0);
08209   hHitsPerPlN_1XCut->SetLineColor(2);
08210   //hHitsPerPlN_1XCut->SetBit(TH1::kCanRebin);
08211 
08212   TH1F *hHitsPerPlN=new TH1F("hHitsPerPlN","hHitsPerPlN",
08213                                200,-1,12);
08214   hHitsPerPlN->SetTitle("Number of Hits per Plane");
08215   hHitsPerPlN->GetXaxis()->SetTitle("Number of Hits per Plane");
08216   hHitsPerPlN->GetXaxis()->CenterTitle();
08217   hHitsPerPlN->GetYaxis()->SetTitle("");
08218   hHitsPerPlN->GetYaxis()->CenterTitle();
08219   hHitsPerPlN->SetFillColor(0);
08220   hHitsPerPlN->SetLineColor(4);
08221   //hHitsPerPlN->SetBit(TH1::kCanRebin);
08222 
08223   TH1F *hHitsPerPlInWin=new TH1F("hHitsPerPlInWin","hHitsPerPlInWin",
08224                                200,-1,12);
08225   hHitsPerPlInWin->SetTitle("Number of Hits per Plane");
08226   hHitsPerPlInWin->GetXaxis()->SetTitle("Number of Hits per Plane");
08227   hHitsPerPlInWin->GetXaxis()->CenterTitle();
08228   hHitsPerPlInWin->GetYaxis()->SetTitle("");
08229   hHitsPerPlInWin->GetYaxis()->CenterTitle();
08230   hHitsPerPlInWin->SetFillColor(0);
08231   hHitsPerPlInWin->SetLineColor(6);
08232   //hHitsPerPlInWin->SetBit(TH1::kCanRebin);
08233 
08234   TH1F *hHitsPerPlPeCutN_1=new TH1F("hHitsPerPlPeCutN_1",
08235                                     "hHitsPerPlPeCutN_1",200,-1,12);
08236   hHitsPerPlPeCutN_1->SetTitle("Number of Hits per Plane");
08237   hHitsPerPlPeCutN_1->GetXaxis()->SetTitle("Number of Hits per Plane");
08238   hHitsPerPlPeCutN_1->GetXaxis()->CenterTitle();
08239   hHitsPerPlPeCutN_1->GetYaxis()->SetTitle("");
08240   hHitsPerPlPeCutN_1->GetYaxis()->CenterTitle();
08241   hHitsPerPlPeCutN_1->SetFillColor(0);
08242   hHitsPerPlPeCutN_1->SetLineColor(3);
08243   //hHitsPerPlPeCutN_1->SetBit(TH1::kCanRebin);
08244 
08245   TH1F *hHitsPerPlPeCut10=new TH1F("hHitsPerPlPeCut10",
08246                                    "hHitsPerPlPeCut10",
08247                                    200,-1,12);
08248   hHitsPerPlPeCut10->SetTitle("Number of Hits per Plane");
08249   hHitsPerPlPeCut10->GetXaxis()->SetTitle("Number of Hits per Plane");
08250   hHitsPerPlPeCut10->GetXaxis()->CenterTitle();
08251   hHitsPerPlPeCut10->GetYaxis()->SetTitle("");
08252   hHitsPerPlPeCut10->GetYaxis()->CenterTitle();
08253   hHitsPerPlPeCut10->SetFillColor(0);
08254   //hHitsPerPlPeCut10->SetBit(TH1::kCanRebin);
08255 
08256   TH1F *hHitsPerPlPeCut10N_1=new TH1F("hHitsPerPlPeCut10N_1",
08257                                       "hHitsPerPlPeCut10N_1",
08258                                       200,-1,12);
08259   hHitsPerPlPeCut10N_1->SetTitle("Number of Hits per Plane");
08260   hHitsPerPlPeCut10N_1->GetXaxis()->
08261     SetTitle("Number of Hits per Plane");
08262   hHitsPerPlPeCut10N_1->GetXaxis()->CenterTitle();
08263   hHitsPerPlPeCut10N_1->GetYaxis()->SetTitle("");
08264   hHitsPerPlPeCut10N_1->GetYaxis()->CenterTitle();
08265   hHitsPerPlPeCut10N_1->SetFillColor(0);
08266   hHitsPerPlPeCut10N_1->SetLineColor(2);
08267   //hHitsPerPlPeCut10N_1->SetBit(TH1::kCanRebin);
08268   
08269   TH1F *hHitsPerPlPeCut10N=new TH1F("hHitsPerPlPeCut10N",
08270                                     "hHitsPerPlPeCut10N",
08271                                     200,-1,12);
08272   hHitsPerPlPeCut10N->SetTitle("Number of Hits per Plane");
08273   hHitsPerPlPeCut10N->GetXaxis()->SetTitle("Number of Hits per Plane");
08274   hHitsPerPlPeCut10N->GetXaxis()->CenterTitle();
08275   hHitsPerPlPeCut10N->GetYaxis()->SetTitle("");
08276   hHitsPerPlPeCut10N->GetYaxis()->CenterTitle();
08277   hHitsPerPlPeCut10N->SetFillColor(0);
08278   hHitsPerPlPeCut10N->SetLineColor(4);
08279   //hHitsPerPlPeCut10N->SetBit(TH1::kCanRebin);
08280 
08281   TH1F *hHitsPerPl25N_1=new TH1F("hHitsPerPl25N_1",
08282                                  "hHitsPerPl25N_1",200,-1,12);
08283   hHitsPerPl25N_1->SetTitle("Number of Hits per Plane");
08284   hHitsPerPl25N_1->GetXaxis()->
08285     SetTitle("Number of Hits per Plane");
08286   hHitsPerPl25N_1->GetXaxis()->CenterTitle();
08287   hHitsPerPl25N_1->GetYaxis()->SetTitle("");
08288   hHitsPerPl25N_1->GetYaxis()->CenterTitle();
08289   hHitsPerPl25N_1->SetFillColor(0);
08290   hHitsPerPl25N_1->SetLineColor(2);
08291   //hHitsPerPl25N_1->SetBit(TH1::kCanRebin);
08292 
08293   TH1F *hTofScintDiffLow1=new TH1F("hTofScintDiffLow1",
08294                                    "hTofScintDiffLow1",500,-500,500);
08295   hTofScintDiffLow1->SetTitle("TOF Scint. Time Diff.");
08296   hTofScintDiffLow1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08297   hTofScintDiffLow1->GetXaxis()->CenterTitle();
08298   hTofScintDiffLow1->GetYaxis()->SetTitle("");
08299   hTofScintDiffLow1->GetYaxis()->CenterTitle();
08300   hTofScintDiffLow1->SetFillColor(0);
08301   hTofScintDiffLow1->SetBit(TH1::kCanRebin);
08302 
08303   TH1F *hTofScintDiffLow1N_1=new TH1F("hTofScintDiffLow1N_1",
08304                                    "hTofScintDiffLow1N_1",500,-500,500);
08305   hTofScintDiffLow1N_1->SetTitle("TOF Scint. Time Diff.");
08306   hTofScintDiffLow1N_1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08307   hTofScintDiffLow1N_1->GetXaxis()->CenterTitle();
08308   hTofScintDiffLow1N_1->GetYaxis()->SetTitle("");
08309   hTofScintDiffLow1N_1->GetYaxis()->CenterTitle();
08310   hTofScintDiffLow1N_1->SetFillColor(0);
08311   hTofScintDiffLow1N_1->SetBit(TH1::kCanRebin);
08312 
08313   TH1F *hTofScintDiffLow1N=new TH1F("hTofScintDiffLow1N",
08314                                    "hTofScintDiffLow1N",500,-500,500);
08315   hTofScintDiffLow1N->SetTitle("TOF Scint. Time Diff.");
08316   hTofScintDiffLow1N->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08317   hTofScintDiffLow1N->GetXaxis()->CenterTitle();
08318   hTofScintDiffLow1N->GetYaxis()->SetTitle("");
08319   hTofScintDiffLow1N->GetYaxis()->CenterTitle();
08320   hTofScintDiffLow1N->SetFillColor(0);
08321   hTofScintDiffLow1N->SetBit(TH1::kCanRebin);
08322 
08323   TH1F *hTofScintDiffUp1=new TH1F("hTofScintDiffUp1",
08324                                   "hTofScintDiffUp1",500,-500,500);
08325   hTofScintDiffUp1->SetTitle("TOF Scint. Time Diff.");
08326   hTofScintDiffUp1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08327   hTofScintDiffUp1->GetXaxis()->CenterTitle();
08328   hTofScintDiffUp1->GetYaxis()->SetTitle("");
08329   hTofScintDiffUp1->GetYaxis()->CenterTitle();
08330   hTofScintDiffUp1->SetFillColor(0);
08331   hTofScintDiffUp1->SetBit(TH1::kCanRebin);
08332 
08333   TH1F *hTofScintDiffUp1N_1=new TH1F("hTofScintDiffUp1N_1",
08334                                   "hTofScintDiffUp1N_1",500,-500,500);
08335   hTofScintDiffUp1N_1->SetTitle("TOF Scint. Time Diff.");
08336   hTofScintDiffUp1N_1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08337   hTofScintDiffUp1N_1->GetXaxis()->CenterTitle();
08338   hTofScintDiffUp1N_1->GetYaxis()->SetTitle("");
08339   hTofScintDiffUp1N_1->GetYaxis()->CenterTitle();
08340   hTofScintDiffUp1N_1->SetFillColor(0);
08341   hTofScintDiffUp1N_1->SetBit(TH1::kCanRebin);
08342 
08343   TH1F *hTofScintDiffUp1N=new TH1F("hTofScintDiffUp1N",
08344                                   "hTofScintDiffUp1N",500,-500,500);
08345   hTofScintDiffUp1N->SetTitle("TOF Scint. Time Diff.");
08346   hTofScintDiffUp1N->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08347   hTofScintDiffUp1N->GetXaxis()->CenterTitle();
08348   hTofScintDiffUp1N->GetYaxis()->SetTitle("");
08349   hTofScintDiffUp1N->GetYaxis()->CenterTitle();
08350   hTofScintDiffUp1N->SetFillColor(0);
08351   hTofScintDiffUp1N->SetBit(TH1::kCanRebin);
08352   
08353   TH1F *hTofScintDiff=new TH1F("hTofScintDiff",
08354                                 "hTofScintDiff",500,-500,500);
08355   hTofScintDiff->SetTitle("TOF Scint. Time Diff.");
08356   hTofScintDiff->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08357   hTofScintDiff->GetXaxis()->CenterTitle();
08358   hTofScintDiff->GetYaxis()->SetTitle("");
08359   hTofScintDiff->GetYaxis()->CenterTitle();
08360   hTofScintDiff->SetFillColor(0);
08361   hTofScintDiff->SetBit(TH1::kCanRebin);
08362 
08363   TH1F *hTofScintDiffN_1=new TH1F("hTofScintDiffN_1",
08364                                   "hTofScintDiffN_1",500,-500,500);
08365   hTofScintDiffN_1->SetTitle("TOF Scint. Time Diff.");
08366   hTofScintDiffN_1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08367   hTofScintDiffN_1->GetXaxis()->CenterTitle();
08368   hTofScintDiffN_1->GetYaxis()->SetTitle("");
08369   hTofScintDiffN_1->GetYaxis()->CenterTitle();
08370   hTofScintDiffN_1->SetFillColor(0);
08371   hTofScintDiffN_1->SetLineColor(2);
08372   hTofScintDiffN_1->SetBit(TH1::kCanRebin);
08373 
08374   TH1F *hTofScintDiffN=new TH1F("hTofScintDiffN",
08375                                   "hTofScintDiffN",500,-500,500);
08376   hTofScintDiffN->SetTitle("TOF Scint. Time Diff.");
08377   hTofScintDiffN->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08378   hTofScintDiffN->GetXaxis()->CenterTitle();
08379   hTofScintDiffN->GetYaxis()->SetTitle("");
08380   hTofScintDiffN->GetYaxis()->CenterTitle();
08381   hTofScintDiffN->SetFillColor(0);
08382   hTofScintDiffN->SetLineColor(4);
08383   hTofScintDiffN->SetBit(TH1::kCanRebin);
08384 
08385   TH1F *hTofScintDiff1=new TH1F("hTofScintDiff1",
08386                                 "hTofScintDiff1",500,-500,500);
08387   hTofScintDiff1->SetTitle("TOF Scint. Time Diff.");
08388   hTofScintDiff1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08389   hTofScintDiff1->GetXaxis()->CenterTitle();
08390   hTofScintDiff1->GetYaxis()->SetTitle("");
08391   hTofScintDiff1->GetYaxis()->CenterTitle();
08392   hTofScintDiff1->SetFillColor(0);
08393   hTofScintDiff1->SetBit(TH1::kCanRebin);
08394 
08395   TH1F *hTofScintDiff1N_1=new TH1F("hTofScintDiff1N_1",
08396                                    "hTofScintDiff1N_1",500,-500,500);
08397   hTofScintDiff1N_1->SetTitle("TOF Scint. Time Diff.");
08398   hTofScintDiff1N_1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08399   hTofScintDiff1N_1->GetXaxis()->CenterTitle();
08400   hTofScintDiff1N_1->GetYaxis()->SetTitle("");
08401   hTofScintDiff1N_1->GetYaxis()->CenterTitle();
08402   hTofScintDiff1N_1->SetFillColor(0);
08403   hTofScintDiff1N_1->SetBit(TH1::kCanRebin);
08404 
08405   TH1F *hTofScintDiff1N=new TH1F("hTofScintDiff1N",
08406                                  "hTofScintDiff1N",500,-500,500);
08407   hTofScintDiff1N->SetTitle("TOF Scint. Time Diff.");
08408   hTofScintDiff1N->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08409   hTofScintDiff1N->GetXaxis()->CenterTitle();
08410   hTofScintDiff1N->GetYaxis()->SetTitle("");
08411   hTofScintDiff1N->GetYaxis()->CenterTitle();
08412   hTofScintDiff1N->SetFillColor(0);
08413   hTofScintDiff1N->SetBit(TH1::kCanRebin);
08414 
08415   TH1F *hTofScintDiffLow2=new TH1F("hTofScintDiffLow2",
08416                                    "hTofScintDiffLow2",500,-500,500);
08417   hTofScintDiffLow2->SetTitle("TOF Scint. Time Diff.");
08418   hTofScintDiffLow2->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08419   hTofScintDiffLow2->GetXaxis()->CenterTitle();
08420   hTofScintDiffLow2->GetYaxis()->SetTitle("");
08421   hTofScintDiffLow2->GetYaxis()->CenterTitle();
08422   hTofScintDiffLow2->SetFillColor(0);
08423   hTofScintDiffLow2->SetLineColor(2);
08424   hTofScintDiffLow2->SetBit(TH1::kCanRebin);
08425 
08426   TH1F *hTofScintDiffLow2N_1=new TH1F("hTofScintDiffLow2N_1",
08427                                       "hTofScintDiffLow2N_1",
08428                                       500,-500,500);
08429   hTofScintDiffLow2N_1->SetTitle("TOF Scint. Time Diff.");
08430   hTofScintDiffLow2N_1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08431   hTofScintDiffLow2N_1->GetXaxis()->CenterTitle();
08432   hTofScintDiffLow2N_1->GetYaxis()->SetTitle("");
08433   hTofScintDiffLow2N_1->GetYaxis()->CenterTitle();
08434   hTofScintDiffLow2N_1->SetFillColor(0);
08435   hTofScintDiffLow2N_1->SetLineColor(2);
08436   hTofScintDiffLow2N_1->SetBit(TH1::kCanRebin);
08437 
08438   TH1F *hTofScintDiffLow2N=new TH1F("hTofScintDiffLow2N",
08439                                     "hTofScintDiffLow2N",
08440                                     500,-500,500);
08441   hTofScintDiffLow2N->SetTitle("TOF Scint. Time Diff.");
08442   hTofScintDiffLow2N->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08443   hTofScintDiffLow2N->GetXaxis()->CenterTitle();
08444   hTofScintDiffLow2N->GetYaxis()->SetTitle("");
08445   hTofScintDiffLow2N->GetYaxis()->CenterTitle();
08446   hTofScintDiffLow2N->SetFillColor(0);
08447   hTofScintDiffLow2N->SetLineColor(2);
08448   hTofScintDiffLow2N->SetBit(TH1::kCanRebin);
08449 
08450   TH1F *hTofScintDiffUp2=new TH1F("hTofScintDiffUp2",
08451                                   "hTofScintDiffUp2",500,-500,500);
08452   hTofScintDiffUp2->SetTitle("TOF Scint. Time Diff.");
08453   hTofScintDiffUp2->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08454   hTofScintDiffUp2->GetXaxis()->CenterTitle();
08455   hTofScintDiffUp2->GetYaxis()->SetTitle("");
08456   hTofScintDiffUp2->GetYaxis()->CenterTitle();
08457   hTofScintDiffUp2->SetFillColor(0);
08458   hTofScintDiffUp2->SetLineColor(2);
08459   hTofScintDiffUp2->SetBit(TH1::kCanRebin);
08460 
08461   TH1F *hTofScintDiffUp2N_1=new TH1F("hTofScintDiffUp2N_1",
08462                                   "hTofScintDiffUp2N_1",500,-500,500);
08463   hTofScintDiffUp2N_1->SetTitle("TOF Scint. Time Diff.");
08464   hTofScintDiffUp2N_1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08465   hTofScintDiffUp2N_1->GetXaxis()->CenterTitle();
08466   hTofScintDiffUp2N_1->GetYaxis()->SetTitle("");
08467   hTofScintDiffUp2N_1->GetYaxis()->CenterTitle();
08468   hTofScintDiffUp2N_1->SetFillColor(0);
08469   hTofScintDiffUp2N_1->SetLineColor(2);
08470   hTofScintDiffUp2N_1->SetBit(TH1::kCanRebin);
08471 
08472   TH1F *hTofScintDiffUp2N=new TH1F("hTofScintDiffUp2N",
08473                                   "hTofScintDiffUp2N",500,-500,500);
08474   hTofScintDiffUp2N->SetTitle("TOF Scint. Time Diff.");
08475   hTofScintDiffUp2N->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08476   hTofScintDiffUp2N->GetXaxis()->CenterTitle();
08477   hTofScintDiffUp2N->GetYaxis()->SetTitle("");
08478   hTofScintDiffUp2N->GetYaxis()->CenterTitle();
08479   hTofScintDiffUp2N->SetFillColor(0);
08480   hTofScintDiffUp2N->SetLineColor(2);
08481   hTofScintDiffUp2N->SetBit(TH1::kCanRebin);
08482 
08483   TH1F *hTofScintDiff2=new TH1F("hTofScintDiff2",
08484                                 "hTofScintDiff2",500,-500,500);
08485   hTofScintDiff2->SetTitle("TOF Scint. Time Diff.");
08486   hTofScintDiff2->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08487   hTofScintDiff2->GetXaxis()->CenterTitle();
08488   hTofScintDiff2->GetYaxis()->SetTitle("");
08489   hTofScintDiff2->GetYaxis()->CenterTitle();
08490   hTofScintDiff2->SetFillColor(0);
08491   hTofScintDiff2->SetLineColor(2);
08492   hTofScintDiff2->SetBit(TH1::kCanRebin);
08493 
08494   TH1F *hTofScintDiff2N_1=new TH1F("hTofScintDiff2N_1",
08495                                    "hTofScintDiff2N_1",500,-500,500);
08496   hTofScintDiff2N_1->SetTitle("TOF Scint. Time Diff.");
08497   hTofScintDiff2N_1->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08498   hTofScintDiff2N_1->GetXaxis()->CenterTitle();
08499   hTofScintDiff2N_1->GetYaxis()->SetTitle("");
08500   hTofScintDiff2N_1->GetYaxis()->CenterTitle();
08501   hTofScintDiff2N_1->SetFillColor(0);
08502   hTofScintDiff2N_1->SetLineColor(2);
08503   hTofScintDiff2N_1->SetBit(TH1::kCanRebin);
08504 
08505   TH1F *hTofScintDiff2N=new TH1F("hTofScintDiff2N",
08506                                  "hTofScintDiff2N",500,-500,500);
08507   hTofScintDiff2N->SetTitle("TOF Scint. Time Diff.");
08508   hTofScintDiff2N->GetXaxis()->SetTitle("TOF Scint. Time Diff.");
08509   hTofScintDiff2N->GetXaxis()->CenterTitle();
08510   hTofScintDiff2N->GetYaxis()->SetTitle("");
08511   hTofScintDiff2N->GetYaxis()->CenterTitle();
08512   hTofScintDiff2N->SetFillColor(0);
08513   hTofScintDiff2N->SetLineColor(2);
08514   hTofScintDiff2N->SetBit(TH1::kCanRebin);
08515 
08516   TH1F *hKovADC1=new TH1F("hKovADC1","KovADC1",400,-5,10000);
08517   hKovADC1->GetXaxis()->SetTitle("KovADC1");
08518   hKovADC1->GetXaxis()->CenterTitle();
08519   hKovADC1->GetYaxis()->SetTitle("");
08520   hKovADC1->GetYaxis()->CenterTitle();
08521   hKovADC1->SetFillColor(0);
08522   hKovADC1->SetBit(TH1::kCanRebin);
08523 
08524   TH1F *hKovADC1N_1=new TH1F("hKovADC1N_1","KovADC1N_1",400,-5,10000);
08525   hKovADC1N_1->GetXaxis()->SetTitle("KovADC1");
08526   hKovADC1N_1->GetXaxis()->CenterTitle();
08527   hKovADC1N_1->GetYaxis()->SetTitle("");
08528   hKovADC1N_1->GetYaxis()->CenterTitle();
08529   hKovADC1N_1->SetFillColor(0);
08530   hKovADC1N_1->SetLineColor(2);
08531   hKovADC1N_1->SetBit(TH1::kCanRebin);
08532 
08533   TH1F *hKovADC1N=new TH1F("hKovADC1N","KovADC1N",400,-5,10000);
08534   hKovADC1N->GetXaxis()->SetTitle("KovADC1");
08535   hKovADC1N->GetXaxis()->CenterTitle();
08536   hKovADC1N->GetYaxis()->SetTitle("");
08537   hKovADC1N->GetYaxis()->CenterTitle();
08538   hKovADC1N->SetFillColor(0);
08539   hKovADC1N->SetLineColor(4);
08540   hKovADC1N->SetBit(TH1::kCanRebin);
08541 
08542   TH1F *hKovADC2=new TH1F("hKovADC2","KovADC2",400,-5,10000);
08543   hKovADC2->GetXaxis()->SetTitle("KovADC2");
08544   hKovADC2->GetXaxis()->CenterTitle();
08545   hKovADC2->GetYaxis()->SetTitle("");
08546   hKovADC2->GetYaxis()->CenterTitle();
08547   hKovADC2->SetFillColor(0);
08548   hKovADC2->SetBit(TH1::kCanRebin);
08549 
08550   TH1F *hKovADC2N_1=new TH1F("hKovADC2N_1","KovADC2N_1",400,-5,10000);
08551   hKovADC2N_1->GetXaxis()->SetTitle("KovADC2");
08552   hKovADC2N_1->GetXaxis()->CenterTitle();
08553   hKovADC2N_1->GetYaxis()->SetTitle("");
08554   hKovADC2N_1->GetYaxis()->CenterTitle();
08555   hKovADC2N_1->SetFillColor(0);
08556   hKovADC2N_1->SetLineColor(2);
08557   hKovADC2N_1->SetBit(TH1::kCanRebin);
08558 
08559   TH1F *hKovADC2N=new TH1F("hKovADC2N","KovADC2N",400,-5,10000);
08560   hKovADC2N->GetXaxis()->SetTitle("KovADC2");
08561   hKovADC2N->GetXaxis()->CenterTitle();
08562   hKovADC2N->GetYaxis()->SetTitle("");
08563   hKovADC2N->GetYaxis()->CenterTitle();
08564   hKovADC2N->SetFillColor(0);
08565   hKovADC2N->SetLineColor(4);
08566   hKovADC2N->SetBit(TH1::kCanRebin);
08567 
08568   TH1F *hKovADC3=new TH1F("hKovADC3","KovADC3",400,-5,10000);
08569   hKovADC3->GetXaxis()->SetTitle("KovADC3");
08570   hKovADC3->GetXaxis()->CenterTitle();
08571   hKovADC3->GetYaxis()->SetTitle("");
08572   hKovADC3->GetYaxis()->CenterTitle();
08573   hKovADC3->SetFillColor(0);
08574   hKovADC3->SetBit(TH1::kCanRebin);
08575 
08576   TH1F *hKovADC3N_1=new TH1F("hKovADC3N_1","KovADC3N_1",400,-5,10000);
08577   hKovADC3N_1->GetXaxis()->SetTitle("KovADC3");
08578   hKovADC3N_1->GetXaxis()->CenterTitle();
08579   hKovADC3N_1->GetYaxis()->SetTitle("");
08580   hKovADC3N_1->GetYaxis()->CenterTitle();
08581   hKovADC3N_1->SetFillColor(0);
08582   hKovADC3N_1->SetLineColor(2);
08583   hKovADC3N_1->SetBit(TH1::kCanRebin);
08584 
08585   TH1F *hKovADC3N=new TH1F("hKovADC3N","KovADC3N",400,-5,10000);
08586   hKovADC3N->GetXaxis()->SetTitle("KovADC3");
08587   hKovADC3N->GetXaxis()->CenterTitle();
08588   hKovADC3N->GetYaxis()->SetTitle("");
08589   hKovADC3N->GetYaxis()->CenterTitle();
08590   hKovADC3N->SetFillColor(0);
08591   hKovADC3N->SetLineColor(4);
08592   hKovADC3N->SetBit(TH1::kCanRebin);
08593 
08594   TH1F *hTofDiff=new TH1F("hTofDiff","hTofDiff",400,-4000,4000);
08595   hTofDiff->GetXaxis()->SetTitle("TOF");
08596   hTofDiff->GetXaxis()->CenterTitle();
08597   hTofDiff->GetYaxis()->SetTitle("");
08598   hTofDiff->GetYaxis()->CenterTitle();
08599   hTofDiff->SetFillColor(0);
08600   hTofDiff->SetBit(TH1::kCanRebin);
08601 
08602   TH1F *hTofDiffN_1=new TH1F("hTofDiffN_1","hTofDiffN_1",400,-4000,4000);
08603   hTofDiffN_1->GetXaxis()->SetTitle("TOF");
08604   hTofDiffN_1->GetXaxis()->CenterTitle();
08605   hTofDiffN_1->GetYaxis()->SetTitle("");
08606   hTofDiffN_1->GetYaxis()->CenterTitle();
08607   hTofDiffN_1->SetFillColor(0);
08608   hTofDiffN_1->SetLineColor(2);
08609   hTofDiffN_1->SetBit(TH1::kCanRebin);
08610 
08611   TH1F *hTofDiffN=new TH1F("hTofDiffN","hTofDiffN",400,-4000,4000);
08612   hTofDiffN->GetXaxis()->SetTitle("TOF");
08613   hTofDiffN->GetXaxis()->CenterTitle();
08614   hTofDiffN->GetYaxis()->SetTitle("");
08615   hTofDiffN->GetYaxis()->CenterTitle();
08616   hTofDiffN->SetFillColor(0);
08617   hTofDiffN->SetLineColor(4);
08618   hTofDiffN->SetBit(TH1::kCanRebin);
08619 
08620   TH1F *hAvStrip=new TH1F("hAvStrip","hAvStrip",25,-1,24);
08621   hAvStrip->GetXaxis()->SetTitle("Average Strip");
08622   hAvStrip->GetXaxis()->CenterTitle();
08623   hAvStrip->GetYaxis()->SetTitle("");
08624   hAvStrip->GetYaxis()->CenterTitle();
08625   hAvStrip->SetFillColor(0);
08626   hAvStrip->SetBit(TH1::kCanRebin);
08627 
08628   TH1F *hAvStripN_1=new TH1F("hAvStripN_1","hAvStripN_1",25,-1,24);
08629   hAvStripN_1->GetXaxis()->SetTitle("Average Strip");
08630   hAvStripN_1->GetXaxis()->CenterTitle();
08631   hAvStripN_1->GetYaxis()->SetTitle("");
08632   hAvStripN_1->GetYaxis()->CenterTitle();
08633   hAvStripN_1->SetFillColor(0);
08634   hAvStripN_1->SetLineColor(2);
08635   hAvStripN_1->SetBit(TH1::kCanRebin);
08636 
08637   TH1F *hAvStripN=new TH1F("hAvStripN","hAvStripN",25,-1,24);
08638   hAvStripN->GetXaxis()->SetTitle("Average Strip");
08639   hAvStripN->GetXaxis()->CenterTitle();
08640   hAvStripN->GetYaxis()->SetTitle("");
08641   hAvStripN->GetYaxis()->CenterTitle();
08642   hAvStripN->SetFillColor(0);
08643   hAvStripN->SetLineColor(4);
08644   hAvStripN->SetBit(TH1::kCanRebin);
08645 
08646   TH1F *hFirstPlane=new TH1F("hFirstPlane",
08647                              "hFirstPlane",77,-2,75);
08648   hFirstPlane->GetXaxis()->SetTitle("First Plane");
08649   hFirstPlane->GetXaxis()->CenterTitle();
08650   hFirstPlane->GetYaxis()->SetTitle("");
08651   hFirstPlane->GetYaxis()->CenterTitle();
08652   hFirstPlane->SetFillColor(0);
08653   hFirstPlane->SetBit(TH1::kCanRebin);
08654 
08655   TH1F *hFirstPlaneN_1=new TH1F("hFirstPlaneN_1",
08656                                 "hFirstPlaneN_1",77,-2,75);
08657   hFirstPlaneN_1->GetXaxis()->SetTitle("First Plane");
08658   hFirstPlaneN_1->GetXaxis()->CenterTitle();
08659   hFirstPlaneN_1->GetYaxis()->SetTitle("");
08660   hFirstPlaneN_1->GetYaxis()->CenterTitle();
08661   hFirstPlaneN_1->SetFillColor(0);
08662   hFirstPlaneN_1->SetLineColor(2);
08663   hFirstPlaneN_1->SetBit(TH1::kCanRebin);
08664 
08665   TH1F *hFirstPlaneN=new TH1F("hFirstPlaneN",
08666                               "hFirstPlaneN",77,-2,75);
08667   hFirstPlaneN->GetXaxis()->SetTitle("First Plane");
08668   hFirstPlaneN->GetXaxis()->CenterTitle();
08669   hFirstPlaneN->GetYaxis()->SetTitle("");
08670   hFirstPlaneN->GetYaxis()->CenterTitle();
08671   hFirstPlaneN->SetFillColor(0);
08672   hFirstPlaneN->SetLineColor(4);
08673   hFirstPlaneN->SetBit(TH1::kCanRebin);
08674 
08675   TH1F* hLowEn=new TH1F("hLowEn","hLowEn",6000,-1,20);
08676   hLowEn->SetTitle("hLowEn");
08677   hLowEn->GetXaxis()->SetTitle("hLowEn");
08678   hLowEn->GetXaxis()->CenterTitle();
08679   hLowEn->SetFillColor(0);
08680   hLowEn->SetLineWidth(3);
08681   //hLowEn->SetBit(TH1::kCanRebin);
08682 
08683   TH1F* hHighEn=new TH1F("hHighEn","hHighEn",6000,-1,20);
08684   hHighEn->SetTitle("hHighEn");
08685   hHighEn->GetXaxis()->SetTitle("hHighEn");
08686   hHighEn->GetXaxis()->CenterTitle();
08687   hHighEn->SetFillColor(0);
08688   //hHighEn->SetBit(TH1::kCanRebin);
08689 
08690   vector<TProfile*> pSigCorVsDist;
08691   vector<TProfile*> pSigCorVsDistN;
08692   vector<Int_t> vWindowSize;
08693   vector<Float_t> bigAv;
08694   vector<Int_t> bigAvCounter;
08695   Float_t sum15_18=0;
08696   Float_t sum15_18Counter=0;
08697   Float_t sum15_18Mip=0;
08698   Float_t sum15_18MipCounter=0;
08699   Float_t sumSigCorTotal=0;
08700   Float_t sumSigCorTotalCounter=0;
08701   Float_t sumMipTotal=0;
08702   Float_t sumMipTotalCounter=0;
08703 
08704   //num maps for all stripends
08705   map<Int_t,Float_t> num;
08706   map<Int_t,Float_t> numX;
08707   map<Int_t,Float_t> numT;
08708   map<Int_t,Float_t> numOs;
08709   map<Int_t,Float_t> numOsX;
08710   map<Int_t,Float_t> numOsT;
08711 
08712   //non-offset num maps for individual stripends
08713   map<Int_t,Float_t> numO1;
08714   map<Int_t,Float_t> numO1X;
08715   map<Int_t,Float_t> numO1T;
08716   map<Int_t,Float_t> numO2;
08717   map<Int_t,Float_t> numO2X;
08718   map<Int_t,Float_t> numO2T;
08719   map<Int_t,Float_t> numE1;
08720   map<Int_t,Float_t> numE1X;
08721   map<Int_t,Float_t> numE1T;
08722   map<Int_t,Float_t> numE2;
08723   map<Int_t,Float_t> numE2X;
08724   map<Int_t,Float_t> numE2T;
08725 
08726   //offset num maps for individual stripends
08727   map<Int_t,Float_t> numOsO1;
08728   map<Int_t,Float_t> numOsO1X;
08729   map<Int_t,Float_t> numOsO1T;
08730   map<Int_t,Float_t> numOsO2;
08731   map<Int_t,Float_t> numOsO2X;
08732   map<Int_t,Float_t> numOsO2T;
08733   map<Int_t,Float_t> numOsE1;
08734   map<Int_t,Float_t> numOsE1X;
08735   map<Int_t,Float_t> numOsE1T;
08736   map<Int_t,Float_t> numOsE2;
08737   map<Int_t,Float_t> numOsE2X;
08738   map<Int_t,Float_t> numOsE2T;
08739 
08740   Int_t passPidCounter=0;
08741   Int_t straightTrackCounter=0;
08742   Int_t NCutsCounter=0;
08743 
08744   //txt file to hold events
08745 
08746   ofstream& eventsTxtFile=(*(this->OpenTxtFile(fRunNumber,
08747                                                 "myevents")));
08748   ofstream& eventsTxtFileHpp=(*(this->OpenTxtFile(fRunNumber,
08749                                                   "myeventsHpp")));
08750   ofstream& eventsTxtFileHpp10=(*(this->OpenTxtFile(fRunNumber,
08751                                                    "myeventsHpp10")));
08752   ofstream& eventsTxtFilePSMu=(*(this->OpenTxtFile(fRunNumber,
08753                                                    "myeventsPSMu")));
08754   ofstream& eventsTxtFileOL=(*(this->OpenTxtFile(fRunNumber,
08755                                                  "myeventsOL")));
08756   ofstream& eventsTxtFileFidVol=
08757     (*(this->OpenTxtFile(fRunNumber,"myeventsFidVol")));
08758   ofstream& eventsTxtFileStrips25=(*(this->OpenTxtFile
08759                                      (fRunNumber,"myeventsStrips25")));
08760   ofstream& eventsTxtFileLowPlanesHit=
08761     (*(this->OpenTxtFile(fRunNumber,"myeventsLowPlanesHit")));
08762 
08766   
08767   this->InitialiseLoopVariables();  
08768   
08769   for(Int_t event=0;event<fEvents;event++){
08770     
08771     this->SetLoopVariables(event);
08772 
08773     //the dead chips should be random and so can be done here
08774     if (this->CutOnDeadChips()) continue;
08775     //only do full analysis if time is greater than minRunTime
08776     if (ts.GetSec()<minRunTime){
08777       if (this->CutOnPid()) continue;
08778     }
08779 
08780     map<Int_t,Float_t> planeSigCor;
08781     map<Int_t,Float_t> planeSigCorX;
08782     map<Int_t,Float_t> planeSigCorT;
08783     map<Int_t,Float_t> planeSigCorO1;    
08784     map<Int_t,Float_t> planeSigCorO1X;
08785     map<Int_t,Float_t> planeSigCorO1T;
08786     map<Int_t,Float_t> planeSigCorO2;
08787     map<Int_t,Float_t> planeSigCorO2X;
08788     map<Int_t,Float_t> planeSigCorO2T;
08789     map<Int_t,Float_t> planeSigCorE1;
08790     map<Int_t,Float_t> planeSigCorE1X;
08791     map<Int_t,Float_t> planeSigCorE1T;
08792     map<Int_t,Float_t> planeSigCorE2;
08793     map<Int_t,Float_t> planeSigCorE2X;
08794     map<Int_t,Float_t> planeSigCorE2T;
08795 
08796     map<Int_t,Float_t> planeMip;
08797     map<Int_t,Float_t> planeMipX;
08798     map<Int_t,Float_t> planeMipT;
08799 
08800     //Int_t numHits=0;
08801 
08802     map<Int_t,map<Int_t,Float_t> > stplSigCor;
08803     map<Int_t,map<Int_t,Float_t> > stplNum;
08804 
08805     Int_t lowTrkStrip=25;//stores the lowest tracked strip
08806     Int_t upTrkStrip=-1;
08807     Int_t lowTrkStripPeCut=25;
08808     Int_t upTrkStripPeCut=-1;
08809 
08810     vector<Float_t> vTimes1;//store all the times
08811     vector<Float_t> vTimes2;//store all the times
08812     vTimes1.reserve(100);
08813     vTimes2.reserve(100);
08814 
08815     //get tclones arrays for this snarl
08816     TClonesArray &cTrk=*fTrkHitInfo;
08817     Int_t numTrkHits=fTrkHitInfo->GetEntries();
08818     TClonesArray &cUnTrk = *fUnTrkHitInfo;
08819     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
08820     //CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
08821     TClonesArray &cXTalk = *fXTalkHits;
08822     Int_t numXTalkHits=fXTalkHits->GetEntries();
08823 
08825     //loop over the untracked hits in the snarl
08827     for (Int_t hit=0;hit<numUnTrkHits;hit++){
08828       //cast the tclonesarray up to a trackedhitinfo object
08829       CDTrackedHitInfo *hitInfo=
08830         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
08831 
08832       this->ReadInHitInfo(hitInfo);
08833 
08834       //cut out the bad channels
08835       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
08836 
08837       //check the channel's sanity
08838       this->StandardSanityChecks();
08839 
08840       //calc the number of planes hit
08841       this->CalcNumPlanesHit(fPlane,fChargePe);
08842 
08843       //calc the scint hits time difference compared to tof
08844       this->CalcLowUpScint_TofDiff(fTime);
08845       //store the times
08846       if (fStripend==2 || 
08847           (fStripend==1 && fPlane==0 && fRunNumber>70000)) {
08848         vTimes2.push_back(fTime);
08849       }
08850       else if (fStripend==1) vTimes1.push_back(fTime);
08851           
08852       //cut out the channels not to be used in calorimetry
08853       if (this->CutOnBadCalorimetry(fPlane,fStrip,fStripend)) continue;
08854 
08855       //do the calibration again with latest tables, temperatures,etc
08856       fChargeSigCor=this->ReCalibrate(fChargeAdc,
08857                                       fPlane,fStrip,fStripend);
08858 
08859       //store the plane and strip info
08860       (stplSigCor[fPlane])[fStrip]+=fChargeSigCor;
08861       (stplNum[fPlane])[fStrip]++;
08862 
08863       //add up the charge of the hits in each plane
08864       planeSigCorX[fPlane]+=fChargeSigCor;
08865       planeSigCorT[fPlane]+=fChargeSigCor;
08866       planeMipX[fPlane]+=fChargeMip;
08867       planeMipT[fPlane]+=fChargeMip;
08868       if (fO1) planeSigCorO1X[fPlane]+=fChargeSigCor;
08869       if (fO2) planeSigCorO2X[fPlane]+=fChargeSigCor;
08870       if (fE1) planeSigCorE1X[fPlane]+=fChargeSigCor;
08871       if (fE2) planeSigCorE2X[fPlane]+=fChargeSigCor;
08872       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
08873       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
08874       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
08875       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
08876 
08877       if (fStripend==1) pStVsPl1->Fill(fPlane,fStrip,fChargeSigCor);
08878       if (fStripend==2) pStVsPl2->Fill(fPlane,fStrip,fChargeSigCor);
08879       if (fStripend==1) hStVsPl1->Fill(fPlane,fStrip);
08880       if (fStripend==2) hStVsPl2->Fill(fPlane,fStrip);
08881     }
08882 
08884     //loop over xtalk hits in the snarl
08886     for (Int_t hit=0;hit<numXTalkHits;hit++){
08887       CDXTalkHitInfo *hitInfo=
08888         dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
08889 
08890       this->ReadInHitInfo(hitInfo);
08891       
08892       //cut out the bad channels
08893       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
08894 
08895       //check the channel's sanity
08896       this->StandardSanityChecks();
08897 
08898       //calc the number of planes hit
08899       this->CalcNumPlanesHit(fPlane,fChargePe);
08900 
08901       //calc the scint hits time difference compared to tof
08902       this->CalcLowUpScint_TofDiff(fTime);
08903       //store the times
08904       if (fStripend==2 || 
08905           (fStripend==1 && fPlane==0 && fRunNumber>70000)) {
08906         vTimes2.push_back(fTime);
08907       }
08908       else if (fStripend==1) vTimes1.push_back(fTime);
08909 
08910       //cut out the channels not to be used in calorimetry
08911       if (this->CutOnBadCalorimetry(fPlane,fStrip,fStripend)) continue;
08912 
08913       //do the calibration again with latest tables, temperatures,etc
08914       fChargeSigCor=this->ReCalibrate(fChargeAdc,
08915                                       fPlane,fStrip,fStripend);
08916 
08917       //store the plane and strip info
08918       (stplSigCor[fPlane])[fStrip]+=fChargeSigCor;
08919       (stplNum[fPlane])[fStrip]++;
08920 
08921       //add up the charge of the hits in each plane
08922       planeSigCorX[fPlane]+=fChargeSigCor;
08923       planeSigCorT[fPlane]+=fChargeSigCor;
08924       planeMipX[fPlane]+=fChargeMip;
08925       planeMipT[fPlane]+=fChargeMip;
08926       if (fO1) planeSigCorO1X[fPlane]+=fChargeSigCor;
08927       if (fO2) planeSigCorO2X[fPlane]+=fChargeSigCor;
08928       if (fE1) planeSigCorE1X[fPlane]+=fChargeSigCor;
08929       if (fE2) planeSigCorE2X[fPlane]+=fChargeSigCor;
08930       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
08931       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
08932       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
08933       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
08934 
08935       if (fStripend==1) pStVsPl1->Fill(fPlane,fStrip,fChargeSigCor);
08936       if (fStripend==2) pStVsPl2->Fill(fPlane,fStrip,fChargeSigCor);
08937       if (fStripend==1) hStVsPl1->Fill(fPlane,fStrip);
08938       if (fStripend==2) hStVsPl2->Fill(fPlane,fStrip);
08939     }
08940 
08942     //loop over the tracked hits
08944     for (Int_t hit=0;hit<numTrkHits;hit++){
08945       CDTrackedHitInfo *trackedHitInfo=
08946         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
08947           
08948       this->ReadInHitInfo(trackedHitInfo);
08949 
08950       //cut out the bad channels
08951       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
08952 
08953       //check the channel's sanity
08954       this->StandardSanityChecks();
08955 
08956       //calc the number of planes hit
08957       this->CalcNumPlanesHit(fPlane,fChargePe);
08958 
08959       //calculate the first and last planes
08960       this->CalcFirstLastPlane(fPlane);
08961       //calc the average strip for the ps muon cut
08962       this->CalcAvStripForPSMuonCut(fPlane,fStrip,fStripend);
08963 
08964       //calc the lowest and highest tracked strips
08965       if (fStrip<lowTrkStrip) lowTrkStrip=fStrip;
08966       if (fStrip>upTrkStrip) upTrkStrip=fStrip;
08967       if (fChargePe>1.5){
08968         if (fStrip<lowTrkStripPeCut) lowTrkStripPeCut=fStrip;
08969         if (fStrip>upTrkStripPeCut) upTrkStripPeCut=fStrip;
08970       }
08971 
08972       //calc the scint hits time difference compared to tof
08973       this->CalcLowUpScint_TofDiff(fTime);
08974       //store the times
08975       if (fStripend==2 || 
08976           (fStripend==1 && fPlane==0 && fRunNumber>70000)) {
08977         vTimes2.push_back(fTime);
08978       }
08979       else if (fStripend==1) vTimes1.push_back(fTime);
08980 
08981       //cut out the channels not to be used in calorimetry
08982       if (this->CutOnBadCalorimetry(fPlane,fStrip,fStripend)) continue;
08983 
08984       //do the calibration again with latest tables, temperatures,etc
08985       fChargeSigCor=this->ReCalibrate(fChargeAdc,
08986                                       fPlane,fStrip,fStripend);
08987 
08988       //store the plane and strip info
08989       (stplSigCor[fPlane])[fStrip]+=fChargeSigCor;
08990       (stplNum[fPlane])[fStrip]++;
08991 
08992       //add up the charge of the hits in each plane
08993       planeSigCor[fPlane]+=fChargeSigCor;
08994       planeSigCorT[fPlane]+=fChargeSigCor;
08995       planeMip[fPlane]+=fChargeMip;
08996       planeMipT[fPlane]+=fChargeMip;
08997 
08998       if (fO1) planeSigCorO1[fPlane]+=fChargeSigCor;
08999       if (fO2) planeSigCorO2[fPlane]+=fChargeSigCor;
09000       if (fE1) planeSigCorE1[fPlane]+=fChargeSigCor;
09001       if (fE2) planeSigCorE2[fPlane]+=fChargeSigCor;
09002       if (fO1) planeSigCorO1T[fPlane]+=fChargeSigCor;
09003       if (fO2) planeSigCorO2T[fPlane]+=fChargeSigCor;
09004       if (fE1) planeSigCorE1T[fPlane]+=fChargeSigCor;
09005       if (fE2) planeSigCorE2T[fPlane]+=fChargeSigCor;
09006 
09007       if (fStripend==1) pStVsPl1->Fill(fPlane,fStrip,fChargeSigCor);
09008       if (fStripend==2) pStVsPl2->Fill(fPlane,fStrip,fChargeSigCor);
09009       if (fStripend==1) hStVsPl1->Fill(fPlane,fStrip);
09010       if (fStripend==2) hStVsPl2->Fill(fPlane,fStrip);
09011     }
09013     //end of loop over the tracked hits
09015 
09016     //get the number of planes
09017     const Float_t numPlanesHit=fNumPlanesHitAll.size();
09018     const Float_t numPlanesHit25=fNumPlanesHit25.size();
09019     const Float_t numPlanesHitPeCut=fNumPlanesHitPeCut.size();
09020     const Float_t numPlanesHitPeCut10=fNumPlanesHitPeCut10.size();
09021 
09022     //calc the number of hits
09023     const Float_t numHits=this->SumMapValues(fNumPlanesHitAll);
09024     const Float_t numHits25=this->SumMapValues(fNumPlanesHit25);
09025     const Float_t numHitsPeCut=this->SumMapValues(fNumPlanesHitPeCut);
09026     const Float_t numHitsPeCut10=this->
09027       SumMapValues(fNumPlanesHitPeCut10);
09028 
09029     //calc the number of hits per plane
09030     const Float_t numHitsPerPlane=(numPlanesHit>0)?
09031       numHits/numPlanesHit:-0.5;
09032     const Float_t numHitsPerPlane25=(numPlanesHit25>0)?
09033       numHits25/numPlanesHit25:-0.5;
09034     const Float_t numHitsPerPlanePeCut=(numPlanesHitPeCut>0)?
09035       numHitsPeCut/numPlanesHitPeCut:-0.5;
09036     const Float_t numHitsPerPlanePeCut10=(numPlanesHitPeCut10>0)?
09037       numHitsPeCut10/numPlanesHitPeCut10:-0.5;
09038 
09039     const Int_t lowStripsFromCentre=12-lowTrkStrip;
09040     const Int_t upStripsFromCentre=upTrkStrip-11;
09041     const Int_t stripsFromCentre=
09042       (upStripsFromCentre>lowStripsFromCentre)?
09043       upStripsFromCentre:lowStripsFromCentre;
09044     const Int_t lowStripsFromCentrePeCut=12-lowTrkStripPeCut;
09045     const Int_t upStripsFromCentrePeCut=upTrkStripPeCut-11;
09046     const Int_t stripsFromCentrePeCut=
09047       (upStripsFromCentrePeCut>lowStripsFromCentrePeCut)?
09048       upStripsFromCentrePeCut:lowStripsFromCentrePeCut;
09049     
09050     const Int_t eventLength=this->GetEventLength();
09051 
09052     //set the globals (do this before cut booleans)
09053     fNumHitsPerPlane=numHitsPerPlane;
09054     fNumHitsPerPlane25=numHitsPerPlane25;
09055     fNumHitsPerPlanePeCut10=numHitsPerPlanePeCut10;
09056     fStripsFromCentrePeCut=stripsFromCentrePeCut;
09057 
09058     //official cuts
09059     Bool_t passesPidCut=!this->CutOnPid();
09060     Bool_t passesEventLengthCut=!this->CutOnEventLength();
09061     //MAXMSG("CDAnalysis",Msg::kInfo,200)
09062     //<<"Nasty, fiducial volume hack..."<<endl;
09063     //Bool_t passesFiducialVolumeCut=true;
09064     Bool_t passesFiducialVolumeCut=!this->CutOnFiducialVolume();
09065     Bool_t passesTrackQualityCut=!this->CutOnTrackQuality(true);
09066     Bool_t passesScint_TofDiffCut=!this->CutOnScint_TofDiff();
09067     Bool_t passesPSMuonsCut=!this->CutOnPSMuons();
09068     Bool_t passesNumHitsPerPlane10Cut=!this->CutOnNumHitsPerPlane10();
09069     Bool_t passesNumHitsPerPlaneCut=!this->CutOnNumHitsPerPlane();
09070 
09071     Bool_t passesAllCuts=passesPidCut &&
09072       passesEventLengthCut &&
09073       passesFiducialVolumeCut &&
09074       passesTrackQualityCut &&
09075       passesScint_TofDiffCut &&
09076       passesPSMuonsCut &&
09077       passesNumHitsPerPlane10Cut &&
09078       passesNumHitsPerPlaneCut;
09079     
09080     //other cuts (not used in final analysis)
09081     Bool_t passesOverlapCut=!this->CutOnOverlap();
09082 
09084 
09085     //pid cut
09086     hKovADC1->Fill(fKovADC1);
09087     hKovADC2->Fill(fKovADC2);
09088     hKovADC3->Fill(fKovADC3);
09089     hTofDiff->Fill(fTofTDC2-fTofTDC0); 
09090 
09091     //event length cut
09092     hEventLength->Fill(eventLength);
09093 
09094     //fiducial volume cut
09095     hStripsFromCentrePeCut->Fill(stripsFromCentrePeCut);
09096 
09097     //track quality cut
09098     hFirstPlane->Fill(fFirstPlane);
09099 
09100     //timing cut     
09101     MAXMSG("CDAnalysis",Msg::kDebug,500)
09102       <<"vTimes1 size="<<vTimes1.size()
09103       <<", vTimes2 size="<<vTimes2.size()<<endl;
09104     Float_t lowTimeDiff1=500;
09105     Float_t upTimeDiff1=-500;
09106     Float_t lowTimeDiff2=500;
09107     Float_t upTimeDiff2=-500;
09108     Float_t lowTime=2e9;
09109     Float_t upTime=0;
09110     for (vector<Float_t>::iterator tIt=vTimes1.begin();
09111          tIt!=vTimes1.end();++tIt){
09112       Float_t timeDiff=((*tIt)*1e9)-(fTofADCTimeStamp1*25./16);
09113       if (timeDiff>-2000 && timeDiff<2000){
09114         if ((*tIt)*1e9<lowTime) lowTime=(*tIt)*1e9;
09115         if ((*tIt)*1e9>upTime) upTime=(*tIt)*1e9;
09116         if (timeDiff>upTimeDiff1) upTimeDiff1=timeDiff;
09117         if (timeDiff<lowTimeDiff1) lowTimeDiff1=timeDiff;
09118         hTofScintDiff1->Fill(timeDiff);
09119         hTofScintDiff->Fill(timeDiff);
09120       }
09121       MAXMSG("CDAnalysis",Msg::kDebug,5000)
09122         <<"timeDiff="<<timeDiff
09123         <<", tofT="<<fTofADCTimeStamp1
09124         <<", scintT="<<(*tIt)<<endl;
09125     }
09126     for (vector<Float_t>::iterator tIt=vTimes2.begin();
09127          tIt!=vTimes2.end();++tIt){
09128       Float_t timeDiff=((*tIt)*1e9)-(fTofADCTimeStamp1*25./16);
09129       if (timeDiff>-2000 && timeDiff<2000){
09130         if ((*tIt)*1e9<lowTime) lowTime=(*tIt)*1e9;
09131         if ((*tIt)*1e9>upTime) upTime=(*tIt)*1e9;
09132         if (timeDiff>upTimeDiff2) upTimeDiff2=timeDiff;
09133         if (timeDiff<lowTimeDiff2) lowTimeDiff2=timeDiff;
09134         hTofScintDiff2->Fill(timeDiff);
09135         hTofScintDiff->Fill(timeDiff);
09136       }
09137     }
09138     hTofScintDiffLow1->Fill(lowTimeDiff1);
09139     hTofScintDiffUp1->Fill(upTimeDiff1);
09140     hTofScintDiffLow2->Fill(lowTimeDiff2);
09141     hTofScintDiffUp2->Fill(upTimeDiff2);
09142 
09143     //ps muon cut
09144     hAvStrip->Fill(fAvStrip);
09145 
09146     //hits per plane cut 10
09147     hHitsPerPlPeCut10->Fill(numHitsPerPlanePeCut10);
09148 
09149     //hits per plane cut
09150     hHitsPerPl->Fill(numHitsPerPlane);
09151 
09153 
09154     //fill other histos
09155     hNumHits->Fill(numHits);
09156     hOLChi2->Fill(fOLChi2);
09157     hNumPlanes->Fill(numPlanesHit);
09158 
09159     Float_t meu=-1;
09160     Float_t meuO1=-1;
09161     Float_t meuO2=-1;
09162     Float_t meuE1=-1;
09163     Float_t meuE2=-1;
09164 
09165     //make copies before doing nasty hack
09166     map<Int_t,Float_t> planeSigCorTOrig=planeSigCorT;
09167     map<Int_t,Float_t> planeSigCorOrig=planeSigCor;
09168     map<Int_t,Float_t> planeSigCorO1TOrig=planeSigCorO1T;
09169     map<Int_t,Float_t> planeSigCorO2TOrig=planeSigCorO2T;
09170     map<Int_t,Float_t> planeSigCorE1TOrig=planeSigCorE1T;
09171     map<Int_t,Float_t> planeSigCorE2TOrig=planeSigCorE2T;
09172 
09173     if (true && fSimFlag==SimFlag::kData){
09174       //do nasty hack for plane 35 - very nasty!!!!
09175       planeSigCor[35]=planeSigCor[33];
09176       planeSigCorT[35]=planeSigCorT[33];
09177       planeSigCorO1T[35]=planeSigCorO1T[33];
09178       planeSigCorO2T[35]=planeSigCorO2T[33];
09179       planeSigCorE1T[35]=planeSigCorE1T[33];
09180       planeSigCorE2T[35]=planeSigCorE2T[33];    
09181     }
09182 
09184     //section for 14_16 window
09186     //make cut on everything BUT event length
09187     if (false) {
09188       //do nothing
09189     }
09190     else {
09191       Float_t localSum14_16=0;
09192       Float_t localSum14_16Counter=0;
09193 
09194       Float_t localSum14_16O1=0;
09195       Float_t localSum14_16O2=0;
09196       Float_t localSum14_16E1=0;
09197       Float_t localSum14_16E2=0;
09198       Int_t planesFromEnd=16;
09199       Int_t windowStart=eventLength-planesFromEnd;
09200       Int_t windowSize=14;
09201 
09202       Float_t localSum14_16NoTrkCut=0;
09203       Float_t localSum14_16NoTrkCutCounter=0;
09204       Int_t windowStartNoTrkCut=static_cast<Int_t>(numPlanesHit)-
09205         planesFromEnd;
09206 
09207       //make temp maps to avoid zeros problem
09208       map<Int_t,Float_t> tempMap=planeSigCorT;
09209       map<Int_t,Float_t> tempMapO1=planeSigCorO1T;
09210       map<Int_t,Float_t> tempMapO2=planeSigCorO2T;
09211       map<Int_t,Float_t> tempMapE1=planeSigCorE1T;
09212       map<Int_t,Float_t> tempMapE2=planeSigCorE2T;
09213       map<Int_t,Int_t> tempNumPlanesHitPeCut=fNumPlanesHitPeCut;
09214 
09215       Int_t hitsInWin=0;
09216 
09217       //loop through the hits in the window
09218       for (Int_t i=0;i<windowSize;i++){
09219         Int_t plane=windowStart-i;
09220         Int_t planeNoTrkCut=windowStartNoTrkCut-i;
09221 
09222         //calculate the best window value
09223         //if fLP=48 then the first plane included is 30
09224         //this is actually the 19th from the end of the track
09225         localSum14_16+=tempMap[plane];//total including xtalk
09226         localSum14_16Counter++;
09227 
09228         //now do odd and even
09229         if (plane%2==1){
09230           localSum14_16O1+=tempMapO1[plane];//total including xtalk
09231           localSum14_16O2+=tempMapO2[plane];//total including xtalk
09232         }
09233         if (plane%2==0){
09234           localSum14_16E1+=tempMapE1[plane];//total including xtalk
09235           localSum14_16E2+=tempMapE2[plane];//total including xtalk
09236         }
09237 
09238         //sum the number of hits in the window
09239         hitsInWin+=tempNumPlanesHitPeCut[plane];
09240 
09241         //calc no trk cut meu
09242         localSum14_16NoTrkCut+=tempMap[planeNoTrkCut];
09243         localSum14_16NoTrkCutCounter++;
09244       }
09245 
09246       //set meu
09247       meu=localSum14_16/windowSize;
09248       meuO1=localSum14_16O1/(windowSize*0.5);
09249       meuO2=localSum14_16O2/(windowSize*0.5);
09250       meuE1=localSum14_16E1/(windowSize*0.5);
09251       meuE2=localSum14_16E2/(windowSize*0.5);
09252 
09253       //calc the number of hits in the window
09254       Float_t hitsPerPlInWin=1.*hitsInWin/windowSize;
09255 
09256       //fill the histo when no trk requirement is made
09257       if (passesPidCut && 
09258           passesOverlapCut && 
09259           !this->CutOnNumPlanesHit(static_cast<Int_t>(numPlanesHit))){
09260         //passesPSMuonsCut){//don't want this - needs track
09261         Float_t meuNoTrkCut=localSum14_16NoTrkCut/windowSize;
09262         h14_16NoTrkCut->Fill(meuNoTrkCut);
09263       }
09264 
09265       //now cut on the track quality and fill histos
09266       Int_t localMinEventLength=14+16+1;//+1 'cause don't want pl. zero
09267       Int_t localMaxEvLen=59;
09268       if (eventLength>localMinEventLength && 
09269           eventLength<localMaxEvLen &&
09270           passesPidCut && 
09271           passesFiducialVolumeCut && 
09272           passesTrackQualityCut &&
09273           passesScint_TofDiffCut &&
09274           passesPSMuonsCut && 
09275           passesNumHitsPerPlane10Cut && 
09276           passesNumHitsPerPlaneCut){
09277         
09278         //make individual stripend plots
09279         //make sure to perform the LAST cut too!
09280         if (passesEventLengthCut){
09281           h14_16O1->Fill(meuO1);
09282           h14_16O2->Fill(meuO2);
09283           h14_16E1->Fill(meuE1);
09284           h14_16E2->Fill(meuE2);
09285           
09286           //fill the histo for trk in both views requirement
09287           if (fResultEven>0 && fResultOdd>0){
09288             h14_16TrkUV->Fill(meu);
09289           }
09290           
09291           hHitsPerPlInWin->Fill(hitsPerPlInWin);
09292         }
09293         
09294         //make plot to look at how MEU varies with ev len cut
09295         //do the lower cut plots
09296         for (Int_t lowerPlCut=59;lowerPlCut>localMinEventLength;
09297              lowerPlCut--){
09298           if (localSum14_16Counter!=0 && eventLength>=lowerPlCut){
09299             MAXMSG("CDAnalysis",Msg::kVerbose,300)
09300               <<"Filling prof: lowerPlCut="<<lowerPlCut
09301               <<", 14_16="<<localSum14_16/windowSize<<endl;
09302             pMeuVsLowEvLenCutN_1->Fill(lowerPlCut,meu);
09303             pMeuVsLowEvLenCutNormN_1->Fill(lowerPlCut,meu);
09304             
09305             //make N-1 cut
09306             Int_t minPlane=0;
09307             Int_t maxPlane=59;
09308             this->GetEvLenMinMax(minPlane,maxPlane);
09309             if (eventLength<=maxPlane){//apply hard cut of maxPlane
09310               pMeuVsLowEvLenCutN->Fill(lowerPlCut,meu);
09311               pMeuVsLowEvLenCutNormN->Fill(lowerPlCut,meu);
09312             }
09313           }
09314         }
09315         //now do the upper cut plots
09316         for (Int_t upperPlCut=31;upperPlCut<=59;upperPlCut++){
09317           if (localSum14_16Counter!=0 && eventLength<=upperPlCut && 
09318               eventLength>31){
09319             MAXMSG("CDAnalysis",Msg::kVerbose,300)
09320               <<"Filling prof: upperPlCut="<<upperPlCut
09321               <<", 14_16="<<meu<<endl;
09322             pMeuVsUpEvLenCutN_1->Fill(upperPlCut,meu);
09323             pMeuVsUpEvLenCutNormN_1->Fill(upperPlCut,meu);
09324             
09325             //make N-1 cut
09326             Int_t minPlane=0;
09327             Int_t maxPlane=59;
09328             this->GetEvLenMinMax(minPlane,maxPlane);
09329             if (eventLength>minPlane){
09330               pMeuVsUpEvLenCutN->Fill(upperPlCut,meu);
09331               pMeuVsUpEvLenCutNormN->Fill(upperPlCut,meu);
09332             }
09333           }
09334         }
09335       }
09336     }
09337 
09338     Float_t meuPLCorrected=-999;
09339     Float_t meuTruePLCorrected=-999;
09340     Float_t GeVPerMeu=-999;
09341    
09342     if (fResultEven==1 && fResultOdd==1){
09343       //this->CalcXYZ();
09344       map<Int_t,TVector3> mPlPos;
09345       map<Int_t,Float_t> mPLCor;
09346       //first calc all the xyz positions
09347       if (this->CalcXYZ(mPlPos)){
09348         //second calculate the PL corrections
09349         if (this->CalcPLCor(mPlPos,mPLCor)){
09350           meuPLCorrected=this->CalcMeuPLCorrected(planeSigCorT,mPLCor,
09351                                                   event,&GeVPerMeu);
09352           if (passesAllCuts) {
09353             this->FillEnVsDist(planeSigCorT,mPLCor,event);
09354             MAXMSG("CDAnalysis",Msg::kInfo,100)
09355               <<"Found GeVPerMeu="<<GeVPerMeu<<endl;
09356             hGeVPerMeu->Fill(GeVPerMeu);
09357           }
09358         }
09359       }
09360 
09361       //now try truth info
09362       map<Int_t,Float_t> mTruePLCor;
09363       Float_t trueGeVPerMeu=-999;
09364       this->TruePLCor(mTruePLCor,event);
09365       meuTruePLCorrected=this->CalcMeuPLCorrected(planeSigCorT,
09366                                                   mTruePLCor,
09367                                                   event,&trueGeVPerMeu);
09368       
09369       MAXMSG("CDAnalysis",Msg::kInfo,100)
09370         <<endl<<"meu="<<meu<<", meuPLCorrected="<<meuPLCorrected
09371         <<", meuTruePLCorrected="<<meuTruePLCorrected
09372         <<endl<<endl;
09373     }
09374    
09375     if (passesPidCut){
09376       //fill the number of planes hit histo
09377       hNumPlanesMuPi->Fill(numPlanesHit);//all events passing pid
09378     }
09379     
09380     //all but num hits per plane
09381     if (passesPidCut && 
09382         passesEventLengthCut && 
09383         passesFiducialVolumeCut && 
09384         passesTrackQualityCut &&
09385         passesScint_TofDiffCut &&
09386         passesPSMuonsCut){
09387       pSigCorVsOLChi2->Fill(fOLChi2,meu);
09388 
09389       //fill number of hits per plane histos
09390       hNumHitsN_1->Fill(numHits);
09391       hHitsPerPlPeCutN_1->Fill(numHitsPerPlanePeCut);
09392 
09393       //now look at effect of hits per plane cut
09394       for (Float_t hpp=0;hpp<12;hpp+=0.1){
09395         if (hpp>numHitsPerPlane) pMeuVsHit_PlCut->Fill(hpp,meu);
09396         if (hpp>numHitsPerPlanePeCut10) pMeuVsHit_PlCut10->
09397                                           Fill(hpp,meu);
09398       }
09399 
09400       //fill the meu histo just for OL failures
09401       if (this->CutOnOverlap()){
09402         h14_16OL->Fill(meu);
09403       }
09404     }
09405 
09406     //all but track quality and ps muon cut
09407     if (passesPidCut && 
09408         passesEventLengthCut && 
09409         passesFiducialVolumeCut && 
09410         passesTrackQualityCut && 
09411         passesScint_TofDiffCut){
09412       if (fAvStrip<9|| fAvStrip>13){
09413         Double_t time=-1;
09414         if (vTimes1.size()) time=vTimes1[0];
09415         MAXMSG("CDAnalysis",Msg::kDebug,100)
09416           <<"ps muon: event="<<event
09417           <<", fAvStrip="<<fAvStrip<<", fStCount="<<fStCount
09418           <<", Time="<<time<<", sec="<<fSec<<endl;
09419       }
09420       Bool_t printPSMuons12=false;
09421       if (printPSMuons12){
09422         if (fAvStrip1<9|| fAvStrip1>13){
09423           Double_t time=-1;
09424           if (vTimes1.size()) time=vTimes1[0];
09425           MAXMSG("CDAnalysis",Msg::kDebug,100)
09426             <<"** ps muon end=1: event="<<event
09427             <<", fAvStrip1="<<fAvStrip1<<", fStCount="<<fStCount1
09428             <<", Time="<<time<<", sec="<<fSec<<endl;
09429         }
09430         if (fAvStrip2<9|| fAvStrip2>13){
09431           Double_t time=-1;
09432           if (vTimes1.size()) time=vTimes1[0];
09433           MAXMSG("CDAnalysis",Msg::kDebug,100)
09434             <<"** ps muon end=2: event="<<event
09435             <<", fAvStrip1="<<fAvStrip2<<", fStCount="<<fStCount2
09436             <<", Time="<<time<<", sec="<<fSec<<endl;
09437         }
09438       }
09439 
09440       //look at OL
09441       if (passesNumHitsPerPlane10Cut && passesNumHitsPerPlaneCut && 
09442           passesPSMuonsCut) {
09443         //make cut on overlap
09444 
09445         MAXMSG("CDAnalysis",Msg::kDebug,100)
09446           <<"strip<="<<upTrkStripPeCut<<", strip>="<<lowTrkStripPeCut
09447           <<", lowFromCent="<<lowStripsFromCentrePeCut
09448           <<", upFromCent="<<upStripsFromCentrePeCut
09449           <<", stFromCent="<<stripsFromCentrePeCut<<endl;
09450         
09451         hStripsFromCentre->Fill(stripsFromCentre);
09452 
09453         for (Int_t s=0;s<=12;s++){
09454           if (s>stripsFromCentre){
09455             pMeuVsStripCut->Fill(s,meu);
09456           }
09457           if (s<stripsFromCentre){
09458             pMeuVsStripCutPeCut->Fill(s,meu);
09459           }
09460         }
09461       }
09462     }
09463     
09464     //count the number of events passing the pid
09465     if (passesPidCut){
09466       passPidCounter++;
09467     }
09468 
09469     //get meu number with various combinations of cuts
09470     //all with pid
09471     if (passesPidCut && 
09472         passesEventLengthCut) hMeuOnlyPID_EventLengthCut->Fill(meu);
09473     if (passesPidCut &&
09474         passesEventLengthCut && 
09475         passesFiducialVolumeCut &&
09476         passesPSMuonsCut) hMeuOnlyPID_EL_FidCut->Fill(meu);
09477     if (passesPidCut &&
09478         passesEventLengthCut && 
09479         passesScint_TofDiffCut) hMeuOnlyPID_EL_TimeCut->Fill(meu);
09480     if (passesPidCut &&
09481         passesEventLengthCut && 
09482         passesFiducialVolumeCut &&
09483         passesPSMuonsCut &&//considered a fid vol cut
09484         passesScint_TofDiffCut) hMeuOnlyPID_EL_Fid_TimeCut->Fill(meu);
09485     if (passesPidCut &&
09486         passesEventLengthCut && 
09487         passesNumHitsPerPlane10Cut &&
09488         passesNumHitsPerPlaneCut) hMeuOnlyPID_EL_HppCut->Fill(meu);
09489     //all without pid
09490     if (passesEventLengthCut) hMeuOnlyEventLengthCut->Fill(meu);
09491     if (passesEventLengthCut && 
09492         passesFiducialVolumeCut &&
09493         passesPSMuonsCut) hMeuOnlyEL_FidCut->Fill(meu);
09494     if (passesEventLengthCut && 
09495         passesScint_TofDiffCut) hMeuOnlyEL_TimeCut->Fill(meu);
09496     if (passesEventLengthCut && 
09497         passesFiducialVolumeCut &&
09498         passesPSMuonsCut &&//considered a fid vol cut
09499         passesScint_TofDiffCut) hMeuOnlyEL_Fid_TimeCut->Fill(meu);
09500     if (passesEventLengthCut && 
09501         passesNumHitsPerPlane10Cut &&
09502         passesNumHitsPerPlaneCut) hMeuOnlyEL_HppCut->Fill(meu);
09503 
09505 
09506     //fill the N_1 histos for pid
09507     if (passesEventLengthCut && 
09508         passesFiducialVolumeCut && 
09509         passesTrackQualityCut && 
09510         passesScint_TofDiffCut && 
09511         passesPSMuonsCut && 
09512         passesNumHitsPerPlane10Cut &&
09513         passesNumHitsPerPlaneCut){
09514       hOLChi2N_1->Fill(fOLChi2);
09515       hKovADC1N_1->Fill(fKovADC1);
09516       hKovADC2N_1->Fill(fKovADC2);
09517       hKovADC3N_1->Fill(fKovADC3);
09518       hTofDiffN_1->Fill(fTofTDC2-fTofTDC0); 
09519       hMeuNoPidCut->Fill(meu);
09520     }
09521 
09522     //fill the N_1 histos for event length cut
09523     if (passesPidCut &&
09524         passesFiducialVolumeCut && 
09525         passesTrackQualityCut &&
09526         passesScint_TofDiffCut &&
09527         passesPSMuonsCut && 
09528         passesNumHitsPerPlane10Cut &&
09529         passesNumHitsPerPlaneCut){
09530       hNumPlanesN_1->Fill(numPlanesHit);//unofficial cut
09531       hEventLengthN_1->Fill(eventLength);
09532       hMeuNoEventLengthCut->Fill(meu);
09533     }
09534 
09535     //fill the N_1 histos for fiducial volume cut
09536     if (passesPidCut &&
09537         passesEventLengthCut &&
09538         passesTrackQualityCut &&
09539         passesScint_TofDiffCut &&
09540         passesPSMuonsCut && 
09541         passesNumHitsPerPlane10Cut &&
09542         passesNumHitsPerPlaneCut){
09543       hStripsFromCentrePeCutN_1->Fill(stripsFromCentrePeCut);
09544       hMeuNoFidVolCut->Fill(meu);
09545       if (!passesFiducialVolumeCut) eventsTxtFileFidVol<<event<<endl;
09546     }
09547 
09548     //fill the N_1 histos for track quality cut
09549     if (passesPidCut &&
09550         passesEventLengthCut &&
09551         passesFiducialVolumeCut && 
09552         passesScint_TofDiffCut &&
09553         //passesPSMuonsCut && //equivalent to finding a track!
09554         passesNumHitsPerPlane10Cut &&
09555         passesNumHitsPerPlaneCut){
09556       hFirstPlaneN_1->Fill(fFirstPlane);
09557       hMeuNoTrackQualityCut->Fill(meu);
09558     }
09559 
09560     //fill the N_1 histos for timing
09561     if (passesPidCut &&
09562         passesEventLengthCut && 
09563         passesFiducialVolumeCut && 
09564         passesTrackQualityCut && 
09565         passesPSMuonsCut && 
09566         passesNumHitsPerPlane10Cut &&
09567         passesNumHitsPerPlaneCut){
09568 
09569       for (vector<Float_t>::iterator tIt=vTimes1.begin();
09570            tIt!=vTimes1.end();++tIt){     
09571         Float_t timeDiff=((*tIt)*1e9)-(fTofADCTimeStamp1*25./16);
09572         if (timeDiff>-2000 && timeDiff<2000){
09573           hTofScintDiff1N_1->Fill(timeDiff);
09574           hTofScintDiffN_1->Fill(timeDiff);
09575         }
09576       }
09577       for (vector<Float_t>::iterator tIt=vTimes2.begin();
09578            tIt!=vTimes2.end();++tIt){
09579         Float_t timeDiff=((*tIt)*1e9)-(fTofADCTimeStamp1*25./16);
09580         if (timeDiff>-2000 && timeDiff<2000){
09581           hTofScintDiff2N_1->Fill(timeDiff);
09582           hTofScintDiffN_1->Fill(timeDiff);
09583         }
09584       }
09585       hTofScintDiffLow1N_1->Fill(lowTimeDiff1);
09586       hTofScintDiffUp1N_1->Fill(upTimeDiff1);
09587       hTofScintDiffLow2N_1->Fill(lowTimeDiff2);
09588       hTofScintDiffUp2N_1->Fill(upTimeDiff2);
09589       
09590       //now look at effect of time cut
09591       for (Int_t t=-500;t<500;t+=20){
09592         
09593         if (t<fLowScint_Tof) pMeuVsLowTimeCutN_1->Fill(t,meu);
09594         if (t>fUpScint_Tof) pMeuVsUpTimeCutN_1->Fill(t,meu);
09595         
09596         Float_t lowTimeCut=-1e9;
09597         Float_t upTimeCut=1e9;
09598         this->GetLowUpTimeCuts(lowTimeCut,upTimeCut);
09599         
09600         //fill the N cuts histos
09601         if (fLowScint_Tof>lowTimeCut && fUpScint_Tof<upTimeCut){//NF
09602           //if (lowTimeDiff>-175 && upTimeDiff<135){//FF
09603           if (t<fLowScint_Tof) pMeuVsLowTimeCutN->Fill(t,meu);
09604           if (t>fUpScint_Tof) pMeuVsUpTimeCutN->Fill(t,meu);
09605         }
09606       }
09607     }
09608 
09609     //fill the N_1 histos for PS muon cut
09610     if (passesPidCut &&
09611         passesEventLengthCut &&
09612         passesFiducialVolumeCut && 
09613         passesTrackQualityCut &&
09614         passesScint_TofDiffCut &&
09615         passesNumHitsPerPlane10Cut &&
09616         passesNumHitsPerPlaneCut){
09617       hAvStripN_1->Fill(fAvStrip);
09618       if (!passesPSMuonsCut) eventsTxtFilePSMu<<event<<endl;
09619       hMeuNoPSMuCut->Fill(meu);
09620     }
09621 
09622     //fill the N_1 histos for hits per plane cut 10
09623     if (passesPidCut &&
09624         passesEventLengthCut &&
09625         passesFiducialVolumeCut && 
09626         passesTrackQualityCut &&
09627         passesScint_TofDiffCut &&
09628         passesPSMuonsCut &&
09629         passesNumHitsPerPlaneCut){
09630       hHitsPerPlPeCut10N_1->Fill(numHitsPerPlanePeCut10);
09631       hMeuNoHitsPerPlane10Cut->Fill(meu);
09632       if (!passesNumHitsPerPlane10Cut) eventsTxtFileHpp10<<event<<endl;
09633     }
09634 
09635     //fill the N_1 histos for hits per plane cut
09636     if (passesPidCut &&
09637         passesEventLengthCut &&
09638         passesFiducialVolumeCut && 
09639         passesTrackQualityCut &&
09640         passesScint_TofDiffCut &&
09641         passesPSMuonsCut &&
09642         passesNumHitsPerPlane10Cut){
09643       hHitsPerPlN_1->Fill(numHitsPerPlane);
09644       hMeuNoHitsPerPlaneCut->Fill(meu);
09645       if (!passesNumHitsPerPlaneCut) eventsTxtFileHpp<<event<<endl;
09646     }
09647     
09649 
09650     //::Stopping cuts
09651     //cut on the pid (this is not always done above)
09652     if (!passesPidCut) continue;
09653     //make event length cuts
09654     if (!passesEventLengthCut) continue;
09655     //cut on fid
09656     if (!passesFiducialVolumeCut) continue;
09657     //make track quality cuts
09658     if (!passesTrackQualityCut) continue;
09659     //cut on the time difference between scint hits and tof hit
09660     if (!passesScint_TofDiffCut) continue;
09661     //cut out ps muons
09662     if (!passesPSMuonsCut) continue;
09663     //cut on the number of hits per plane 10
09664     if (!passesNumHitsPerPlane10Cut) continue;
09665     //cut on the number of hits per plane
09666     if (!passesNumHitsPerPlaneCut) continue;
09667 
09668     //count total events passing cuts
09669     NCutsCounter++;
09670     //write event to txt file
09671     eventsTxtFile<<event<<endl;
09672 
09674 
09675     //pid cut N
09676     hKovADC1N->Fill(fKovADC1);
09677     hKovADC2N->Fill(fKovADC2);
09678     hKovADC3N->Fill(fKovADC3);
09679     hTofDiffN->Fill(fTofTDC2-fTofTDC0);
09680 
09681     //event length cut N
09682     hEventLengthN->Fill(eventLength);
09683 
09684     //fiducial volume cut N
09685     hStripsFromCentrePeCutN->Fill(stripsFromCentrePeCut);
09686 
09687     //track quality cut N
09688     hFirstPlaneN->Fill(fFirstPlane);
09689 
09690     //timing cut N
09691     hTofScintDiffLow1N->Fill(lowTimeDiff1);
09692     hTofScintDiffUp1N->Fill(upTimeDiff1);
09693     hTofScintDiffLow2N->Fill(lowTimeDiff2);
09694     hTofScintDiffUp2N->Fill(upTimeDiff2);
09695     for (vector<Float_t>::iterator tIt=vTimes1.begin();
09696          tIt!=vTimes1.end();++tIt){
09697       Float_t timeDiff=((*tIt)*1e9)-(fTofADCTimeStamp1*25./16);
09698       if (timeDiff>-2000 && timeDiff<2000){
09699         hTofScintDiff1N->Fill(timeDiff);
09700         hTofScintDiffN->Fill(timeDiff);
09701       }
09702     }
09703     for (vector<Float_t>::iterator tIt=vTimes2.begin();
09704          tIt!=vTimes2.end();++tIt){
09705       Float_t timeDiff=((*tIt)*1e9)-(fTofADCTimeStamp1*25./16);
09706       if (timeDiff>-2000 && timeDiff<2000){
09707         hTofScintDiff2N->Fill(timeDiff);
09708         hTofScintDiffN->Fill(timeDiff);
09709       }
09710     }
09711 
09712     //ps muon cut N
09713     hAvStripN->Fill(fAvStrip);
09714     
09715     //hits per plane 10 cut N
09716     hHitsPerPlPeCut10N->Fill(numHitsPerPlanePeCut10);
09717 
09718     //hits per plane cut N
09719     hHitsPerPlN->Fill(numHitsPerPlane);
09720 
09722 
09723     //calc average temperature, using weighted mean
09724     static Int_t avTempCounter=0;
09725     avTempCounter++;
09726     
09727     //get a calibrator
09728     Calibrator& cal=Calibrator::Instance();
09729     //VldTimeStamp (const time_t &t, const Int_t nsec)
09730     VldTimeStamp vldts(fSec,0);
09731     VldContext vc(Detector::kCalDet,fSimFlag,vldts);
09732     cal.ReInitialise(vc);
09733     fTemperature=cal.GetTemperature();
09734 
09735     fAvTemperature=fTemperature*(1./avTempCounter)+
09736       fAvTemperature*((avTempCounter-1.)/avTempCounter);
09737     MAXMSG("CDAnalysis",Msg::kInfo,10)
09738       <<"fTemperature="<<fTemperature
09739       <<", fAvTemperature="<<fAvTemperature
09740       <<", avTempCounter="<<avTempCounter<<endl;
09741 
09742     //see if any events would have been cut out
09743     if (this->CutOnOverlap()) {
09744       eventsTxtFileOL<<event<<endl;
09745     }
09746     else hOLChi2N->Fill(fOLChi2);
09747 
09748     if (fResultEven==1 && fResultOdd==1){
09749       if (meu<=0 || meuPLCorrected<=0){
09750         cout<<"Ahhhhhh MEU less than zero"<<endl;
09751       }
09752       else{
09753         hMeu->Fill(meu);
09754         hMeuPLCor->Fill(meuPLCorrected);
09755         hMeuTruePLCor->Fill(meuTruePLCorrected);
09756       }
09757     }
09758     else{
09759       MAXMSG("CDAnalysis",Msg::kDebug,100)
09760         <<"Track not good in both views"<<endl;
09761     }
09762     hNumPlanesN->Fill(numPlanesHit);
09763     hHitsPerPl25N_1->Fill(numHitsPerPlane25);
09764     if (numHitsPerPlane25>3) {
09765       MAXMSG("CDAnalysis",Msg::kDebug,100)
09766         <<"*******hpp25="<<numHitsPerPlane25
09767         <<", event="<<event<<", size="<<fNumPlanesHit25.size()
09768         <<", numh="<<numHits25<<", size2="<<numPlanesHit25<<endl;
09769       eventsTxtFileStrips25<<event<<endl;
09770     }
09771 
09772     Float_t highEn=-1;
09773     Float_t lowEn=-1;
09774     this->TrueHighLowEn(highEn,lowEn);
09775     hHighEn->Fill(highEn);
09776     hLowEn->Fill(lowEn);
09777     MAXMSG("CDAnalysis",Msg::kInfo,100)
09778       <<"HighEn="<<highEn<<", lowEn="<<lowEn<<endl;
09779 
09780     //look at straightness of tracky events
09781     Double_t radiusCut=0.2;
09782     Bool_t straightTrk=StraightTrack_Radius(radiusCut);
09783     if (straightTrk) straightTrackCounter++;
09784     map<Float_t,Bool_t> mStraightTrk;
09785     for (Float_t r=0.05;r<0.51;r+=0.05){
09786       mStraightTrk[r]=StraightTrack_Radius(r);
09787     }
09788 
09790     //section for response
09792     const Int_t os=eventLength;
09793 
09794     //must fill the profs before looping over the maps because
09795     //zeros will get added to the maps at the window stage!
09796     //use "Orig" maps - made before doing nasty hack!
09797     //fill profs for all stripends
09798     this->FillProfHisto(pSigCorVsPlane,num,planeSigCorOrig);
09799     this->FillProfHisto(pSigCorVsPlaneX,numX,planeSigCorX);
09800     this->FillProfHisto(pSigCorVsPlaneT,numT,planeSigCorTOrig);
09801     //offset
09802     this->FillProfHisto(pSigCorVsOsPlane,numOs,planeSigCorOrig,os);
09803     this->FillProfHisto(pSigCorVsOsPlaneX,numOsX,planeSigCorX,os);
09804     this->FillProfHisto(pSigCorVsOsPlaneT,numOsT,planeSigCorTOrig,os);
09805 
09806     //fill non-offset profs for individual stripends
09807     this->FillProfHisto(pSigCorVsPlaneO1,numO1,planeSigCorO1);
09808     this->FillProfHisto(pSigCorVsPlaneO1X,numO1X,planeSigCorO1X);
09809     this->FillProfHisto(pSigCorVsPlaneO1T,numO1T,planeSigCorO1TOrig);
09810     this->FillProfHisto(pSigCorVsPlaneO2,numO2,planeSigCorO2);
09811     this->FillProfHisto(pSigCorVsPlaneO2X,numO2X,planeSigCorO2X);
09812     this->FillProfHisto(pSigCorVsPlaneO2T,numO2T,planeSigCorO2TOrig);
09813     this->FillProfHisto(pSigCorVsPlaneE1,numE1,planeSigCorE1);
09814     this->FillProfHisto(pSigCorVsPlaneE1X,numE1X,planeSigCorE1X);
09815     this->FillProfHisto(pSigCorVsPlaneE1T,numE1T,planeSigCorE1TOrig);
09816     this->FillProfHisto(pSigCorVsPlaneE2,numE2,planeSigCorE2);
09817     this->FillProfHisto(pSigCorVsPlaneE2X,numE2X,planeSigCorE2X);
09818     this->FillProfHisto(pSigCorVsPlaneE2T,numE2T,planeSigCorE2TOrig);
09819 
09820     //fill offset profs for individual stripends
09821     this->FillProfHisto(pSigCorVsOsPlaneO1,numOsO1,planeSigCorO1,os);
09822     this->FillProfHisto(pSigCorVsOsPlaneO1X,numOsO1X,planeSigCorO1X,os);
09823     this->FillProfHisto(pSigCorVsOsPlaneO1T,numOsO1T,planeSigCorO1TOrig,
09824                         os);
09825     this->FillProfHisto(pSigCorVsOsPlaneO2,numOsO2,planeSigCorO2,os);
09826     this->FillProfHisto(pSigCorVsOsPlaneO2X,numOsO2X,planeSigCorO2X,os);
09827     this->FillProfHisto(pSigCorVsOsPlaneO2T,numOsO2T,planeSigCorO2TOrig,
09828                         os);
09829     this->FillProfHisto(pSigCorVsOsPlaneE1,numOsE1,planeSigCorE1,os);
09830     this->FillProfHisto(pSigCorVsOsPlaneE1X,numOsE1X,planeSigCorE1X,os);
09831     this->FillProfHisto(pSigCorVsOsPlaneE1T,numOsE1T,planeSigCorE1TOrig,
09832                         os);
09833     this->FillProfHisto(pSigCorVsOsPlaneE2,numOsE2,planeSigCorE2,os);
09834     this->FillProfHisto(pSigCorVsOsPlaneE2X,numOsE2X,planeSigCorE2X,os);
09835     this->FillProfHisto(pSigCorVsOsPlaneE2T,numOsE2T,planeSigCorE2TOrig,
09836                         os);
09837 
09839     //section for total event sigcor and mips
09841     Float_t localSumSigCorTotal=0;
09842     Float_t localSumSigCorTotalCounter=0;
09843     for (map<Int_t,Float_t>::iterator sig=planeSigCorT.begin();
09844          sig!=planeSigCorT.end();++sig){
09845       localSumSigCorTotal+=sig->second;
09846       localSumSigCorTotalCounter++;
09847       
09848       //fill histos of all hits. Added June/2007
09849       Int_t pl=sig->first;
09850       if (pl<60) sigCorNoPLCorHistos[pl]->Fill(sig->second);
09851       else cout<<"Ahhhh, plane>=60!!!!!"<<endl;
09852     }
09853 
09854     //add total of this event to the sum of all events 
09855     if (localSumSigCorTotalCounter!=0){
09856       sumSigCorTotal+=localSumSigCorTotal;
09857       sumSigCorTotalCounter++;
09858     }
09859 
09860     Float_t localSumMipTotal=0;
09861     Float_t localSumMipTotalCounter=0;
09862     for (map<Int_t,Float_t>::iterator sig=planeMipT.begin();
09863          sig!=planeMipT.end();++sig){
09864       localSumMipTotal+=sig->second;
09865       localSumMipTotalCounter++;
09866     }
09867 
09868     //add total of this event to the sum of all events 
09869     if (localSumMipTotalCounter!=0){
09870       sumMipTotal+=localSumMipTotal;
09871       sumMipTotalCounter++;
09872     }
09873 
09874     //work out event length
09875     Int_t lastPlNoXTalk=this->CalcLastPlaneOnTrkNoXTalk();
09876     hEvLenFe->Fill(lastPlNoXTalk);
09877     pSigCorVsRange->Fill(lastPlNoXTalk,localSumSigCorTotal);
09878 
09880     //section for sliding window
09882     //Int_t minEventLength=30;
09883 
09884     //initialise the profile histos
09885     static Bool_t firstTime=true;
09886     if (firstTime){
09887       for (Int_t p=18;p>1;p--){
09888         vWindowSize.push_back(p);
09889         bigAv.push_back(0);
09890         bigAvCounter.push_back(0);
09891       }
09892 
09893       for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
09894            windowSize!=vWindowSize.end();++windowSize){
09895         
09896         string sName=Form("%d",*windowSize);
09897         pSigCorVsDist.push_back
09898           (new TProfile(("pSigCorVsDist"+sName).c_str(),
09899                         ("pSigCorVsDist"+sName).c_str(),100,-2,40));
09900         pSigCorVsDistN.push_back
09901           (new TProfile(("pSigCorVsDistN"+sName).c_str(),
09902                         ("pSigCorVsDistN"+sName).c_str(),100,-2,40));
09903       }
09904     }
09905     firstTime=false;
09906 
09907     vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
09908     vector<TProfile*>::iterator profN=pSigCorVsDistN.begin();
09909     vector<Float_t>::iterator av=bigAv.begin();
09910     vector<Int_t>::iterator count=bigAvCounter.begin();
09911     Float_t localSum15_18=0;
09912     Float_t localSum15_18Counter=0;
09913     Float_t localSum15_18Mip=0;
09914     Float_t localSum15_18MipCounter=0;
09915 
09916     Float_t localSum10_16=0;
09917     Float_t localSum10_16Counter=0;
09918     Float_t localSum10_10=0;
09919     Float_t localSum10_10Counter=0;
09920     Float_t localSum14_16=0;
09921     Float_t localSum14_16Counter=0;
09922     Float_t localSum14_10=0;
09923     Float_t localSum14_10Counter=0;
09924     Float_t localSum18_16=0;
09925     Float_t localSum18_16Counter=0;
09926     Float_t localSum18_10=0;
09927     Float_t localSum18_10Counter=0;
09928 
09929     Float_t localSum14_16NoXTalk=0;
09930     Float_t localSum14_16NoXTalkCounter=0;
09931 
09932     //loop over the different window sizes
09933     for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
09934          windowSize!=vWindowSize.end();++windowSize){
09935       
09936       //slide the window along from the end to 40-windowSize
09937       //for (Int_t p=0;p<minEventLength-*windowSize;p++){
09938       for (Int_t p=0;p<60;p++){
09939         Int_t windowStart=eventLength-p;
09940         Int_t windowStartNoXTalk=lastPlNoXTalk-p;
09941 
09942         //don't do unphysical windows
09943         if (windowStart-(*windowSize)<0) continue;
09944 
09945         MAXMSG("CDAnalysis",Msg::kDebug,500)
09946           <<"Window size="<<*windowSize<<", window start="<<windowStart
09947           <<", eventLength-18="<<eventLength-18<<endl;
09948  
09949         //loop through the hits in the window
09950         for (Int_t i=0;i<*windowSize;i++){
09951           Int_t plane=windowStart-i;
09952           Int_t planeNoXTalk=windowStartNoXTalk-i;
09953           
09954           //sum up energy based on track length with no xtalk
09955           if (*windowSize==14 && windowStartNoXTalk==lastPlNoXTalk-16){
09956             localSum14_16NoXTalk+=planeSigCorT[planeNoXTalk];
09957             localSum14_16NoXTalkCounter++;
09958             MAXMSG("CDAnalysis",Msg::kDebug,500)
09959               <<"Win size="<<*windowSize
09960               <<", win start="<<windowStart
09961               <<" (NoXTalk="<<windowStartNoXTalk<<")"
09962               <<", pl="<<plane
09963               <<", plNoXTalk="<<planeNoXTalk
09964               <<", sc="<<planeSigCorT[plane]
09965               <<", scNXT="<<planeSigCorT[planeNoXTalk]
09966               <<endl;
09967           }
09968 
09969           //calculate the best window value
09970           //if fLP=48 then the first plane included is 30
09971           //this is actually the 19th from the end of the track
09972           if (*windowSize==15 && windowStart==eventLength-18){
09973             localSum15_18+=planeSigCorT[plane];//total including xtalk
09974             localSum15_18Counter++;
09975             localSum15_18Mip+=planeMipT[plane];//total including xtalk
09976             localSum15_18MipCounter++;
09977           }
09978 
09979           if (*windowSize==10 && windowStart==eventLength-16){
09980             localSum10_16+=planeSigCorT[plane];//total including xtalk
09981             localSum10_16Counter++;
09982           }
09983           if (*windowSize==10 && windowStart==eventLength-10){
09984             localSum10_10+=planeSigCorT[plane];//total including xtalk
09985             localSum10_10Counter++;
09986           }
09987           if (*windowSize==14 && windowStart==eventLength-16){
09988             Double_t localSigCorT=planeSigCorT[plane];
09989             localSum14_16+=localSigCorT;
09990             localSum14_16Counter++;
09991             meuHistos[plane]->Fill(localSigCorT);
09992 
09993             //fill strip vs plane maps (per strip, not stripend)
09994             map<Int_t,Float_t>::iterator sc=(stplSigCor[plane]).begin();
09995             for (map<Int_t,Float_t>::iterator i=
09996                    (stplNum[plane]).begin();
09997                  i!=(stplNum[plane]).end();++i){
09998               Int_t strip=i->first;
09999               Float_t num=i->second;
10000               Float_t sigCor=sc->second;
10001               MAXMSG("CDAnalysis",Msg::kDebug,500)
10002                 <<"st="<<i->first<<", num="<<i->second<<endl
10003                 <<"st="<<sc->first<<", sc="<<sc->second<<endl;
10004               pStVsPlWin->Fill(plane,strip,sigCor);
10005               hStVsPlNum->Fill(plane,strip,num);
10006 
10007               //iterate to the next
10008               ++sc;
10009             }
10010           }
10011           if (*windowSize==14 && windowStart==eventLength-10){
10012             localSum14_10+=planeSigCorT[plane];//total including xtalk
10013             localSum14_10Counter++;
10014           }
10015           if (*windowSize==18 && windowStart==eventLength-16){
10016             localSum18_16+=planeSigCorT[plane];//total including xtalk
10017             localSum18_16Counter++;
10018           }
10019           if (*windowSize==18 && windowStart==eventLength-10){
10020             localSum18_10+=planeSigCorT[plane];//total including xtalk
10021             localSum18_10Counter++;
10022           }
10023           
10024           (*prof)->Fill(p,planeSigCorT[plane]);
10025           (*profN)->Fill(p,planeSigCorT[plane]);
10026           (*av)+=planeSigCorT[plane];
10027           (*count)++;
10028         }
10029 
10030       }
10031       av++;
10032       count++;
10033       prof++;
10034       profN++;
10035     }
10036 
10037     if (localSum15_18Counter!=0){
10038       h15_18->Fill(localSum15_18/15);
10039       sum15_18+=localSum15_18;//add this event's energy on to total
10040       sum15_18Counter++;
10041       sum15_18Mip+=localSum15_18Mip;
10042       sum15_18MipCounter++;
10043     }
10044 
10045     //fill the no xtalk histo
10046     if (localSum14_16NoXTalkCounter!=0) {
10047       h14_16NoXTalk->Fill(localSum14_16NoXTalk/14);
10048     }
10049 
10050     if (localSum10_16Counter!=0) h10_16->Fill(localSum10_16/10);
10051     if (localSum10_10Counter!=0) h10_10->Fill(localSum10_10/10);
10052     if (localSum14_16Counter!=0) {
10053       h14_16->Fill(localSum14_16/14);
10054       if (straightTrk) h14_16Straight->Fill(localSum14_16/14);
10055       //loop and fill prof with different straightnesses
10056       for (map<Float_t,Bool_t>::iterator sTrk=mStraightTrk.begin();
10057            sTrk!=mStraightTrk.end();++sTrk){
10058         if (sTrk->second){
10059           pMeuVsStraightness->Fill(sTrk->first,localSum14_16/14);
10060           pMeuVsStraightnessN->Fill(sTrk->first,localSum14_16/14);
10061         }
10062         MAXMSG("CDAnalysis",Msg::kVerbose,500)
10063           <<"r="<<sTrk->first<<", straight="<<sTrk->second<<endl;
10064       }
10065     }
10066     if (localSum14_10Counter!=0) h14_10->Fill(localSum14_10/14);
10067     if (localSum18_16Counter!=0) h18_16->Fill(localSum18_16/18);
10068     if (localSum18_10Counter!=0) h18_10->Fill(localSum18_10/18);
10069 
10070     Float_t meu2=localSum14_16/14;
10071     if (fabs(meu-meu2)/(0.5*(meu+meu2+0.0001))>0.001){
10072       MAXMSG("CDAnalysis",Msg::kError,2000)
10073         <<"MEUs differ: meu="<<meu<<", meu2="<<meu2<<endl;
10074     }
10075 
10076     //section to look at the fraction of meu contributed by each strip
10077     if (meu>0){
10078       Int_t minPlane=-1;
10079       Int_t maxPlane=-1;
10080       this->GetEvLenMinMax(minPlane,maxPlane);
10081       MAXMSG("CDAnalysis",Msg::kDebug,20)
10082         <<"size="<<stplSigCor.size()<<endl;
10083       //loop over all possible strips and planes in the track window
10084       for (Int_t p=minPlane-16-14;p<=maxPlane-16;p++){
10085         //get an iterator to the strips for this plane
10086         map<Int_t,map<Int_t,Float_t> >::iterator pIt=stplSigCor.find(p);
10087         for (Int_t s=0;s<24;s++){
10088           Float_t sigCor=0;
10089 
10090           Int_t winLower=eventLength-16-14;
10091           Int_t winUpper=eventLength-16;
10092           MAXMSG("CDAnalysis",Msg::kDebug,2000)
10093             <<"winLower="<<winLower<<", winUpper="<<winUpper<<endl;
10094           //only get the sigcor value if it's in the window
10095           //14 planes, if last==50, then 20<p<=34 = 14 all together
10096           if (p>winLower && p<=winUpper){
10097             MAXMSG("CDAnalysis",Msg::kDebug,2000)
10098               <<"Plane was in window="<<p
10099               <<", winLower="<<winLower<<", winUpper="<<winUpper<<endl;
10100             //check if there were hits in pl
10101             if (pIt!=stplSigCor.end()){
10102               MAXMSG("CDAnalysis",Msg::kDebug,2000)
10103                 <<"Plane had strips hit="<<p<<endl;
10104               map<Int_t,Float_t>::iterator sIt=pIt->second.find(s);
10105               //check if strip has hit
10106               if (sIt!=pIt->second.end()){
10107                 sigCor=sIt->second;
10108                 MAXMSG("CDAnalysis",Msg::kDebug,2000)
10109                   <<"Strip was hit, getting sigCor="<<sigCor<<endl;
10110               }
10111             }
10112           }
10113           Float_t fract=(sigCor/14)/meu;
10114           MAXMSG("CDAnalysis",Msg::kDebug,2000)
10115             <<"p="<<p<<", s="<<s<<", sigCor="<<sigCor
10116             <<", fract="<<fract<<endl;
10117           pStVsPlWinFract->Fill(p,s,fract);
10118         }
10119       }
10120     }//end of if meu
10121 
10122     //look at OLChi2
10123     //else cout<<"event="<<event<<endl;
10124     //make plot of how meu varies with OLChi2
10125     for (Float_t olc=0;olc<10;olc+=0.05){
10126       if (olc>fOLChi2){
10127         MAXMSG("CDAnalysis",Msg::kDebug,2000)
10128           <<"Filling: olc="<<olc<<", fOLChi2="<<fOLChi2<<endl;
10129         pSigCorVsOLChi2Sum->Fill(olc,meu);
10130       }
10131       else {
10132         MAXMSG("CDAnalysis",Msg::kDebug,200)
10133           <<"Not filled: olc="<<olc<<", fOLChi2="<<fOLChi2<<endl;
10134       }
10135     }
10136 
10137     if (1.*numPlanesHit/eventLength<0.9){
10138       MAXMSG("CDAnalysis",Msg::kDebug,100)
10139         <<"low hit planes="<<1.*numPlanesHit/eventLength
10140         <<", event="<<event
10141         <<", TimeDiff=("<<fLowScint_Tof
10142         <<" -> "<<fUpScint_Tof<<")"<<endl
10143         <<"       Time=("<<lowTime
10144         <<" -> "<<upTime<<")"
10145         <<", sec="<<fSec
10146         <<endl;
10147       eventsTxtFileLowPlanesHit<<event<<endl;
10148     }
10149   }//end of for                                       
10150   
10154 
10155   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
10156 
10157   //turn off the stats box printing
10158   gStyle->SetOptStat(0);
10159 
10160   //all stripends
10161   string sTitle="Energy Deposition (SigCor, all Stripends)";
10162   string sXTitle="Distance from end of track (planes)";
10163   this->DrawResponsePlot(sTitle,pSigCorVsPlane,pSigCorVsPlaneX,
10164                          pSigCorVsPlaneT,num,numX,numT);
10165   sTitle="Energy Deposition Vs Distance (SigCor, all Stripends)";
10166   this->DrawResponsePlot(sTitle,pSigCorVsOsPlane,pSigCorVsOsPlaneX,
10167                          pSigCorVsOsPlaneT,numOs,numOsX,numOsT,sXTitle);
10168 
10169   //non-offset planes
10170   sTitle="Energy Deposition (SigCor in Odd Planes FD stripend)";
10171   this->DrawResponsePlot(sTitle,pSigCorVsPlaneO1,pSigCorVsPlaneO1X,
10172                          pSigCorVsPlaneO1T,numO1,numO1X,numO1T);
10173 
10174   sTitle="Energy Deposition (SigCor in Odd Planes ND stripend)";
10175   this->DrawResponsePlot(sTitle,pSigCorVsPlaneO2,pSigCorVsPlaneO2X,
10176                          pSigCorVsPlaneO2T,numO2,numO2X,numO2T);
10177 
10178   sTitle="Energy Deposition (SigCor in Even Planes FD stripend)";
10179   this->DrawResponsePlot(sTitle,pSigCorVsPlaneE1,pSigCorVsPlaneE1X,
10180                          pSigCorVsPlaneE1T,numE1,numE1X,numE1T);
10181 
10182   sTitle="Energy Deposition (SigCor in Even Planes ND stripend)";
10183   this->DrawResponsePlot(sTitle,pSigCorVsPlaneE2,pSigCorVsPlaneE2X,
10184                          pSigCorVsPlaneE2T,numE2,numE2X,numE2T);
10185 
10186   //offset planes
10187   sTitle="Energy Deposition Vs Distance (SigCor in Odd Planes FD stripend)";
10188   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneO1,pSigCorVsOsPlaneO1X,
10189                          pSigCorVsOsPlaneO1T,numOsO1,numOsO1X,numOsO1T,
10190                          sXTitle);
10191 
10192   sTitle="Energy Deposition Vs Distance (SigCor in Odd Planes ND stripend)";
10193   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneO2,pSigCorVsOsPlaneO2X,
10194                          pSigCorVsOsPlaneO2T,numOsO2,numOsO2X,numOsO2T,
10195                          sXTitle);
10196 
10197   sTitle="Energy Deposition Vs Distance (SigCor in Even Planes FD stripend)";
10198   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneE1,pSigCorVsOsPlaneE1X,
10199                          pSigCorVsOsPlaneE1T,numOsE1,numOsE1X,numOsE1T,
10200                          sXTitle);
10201 
10202   sTitle="Energy Deposition Vs Distance (SigCor in Even Planes ND stripend)";
10203   this->DrawResponsePlot(sTitle,pSigCorVsOsPlaneE2,pSigCorVsOsPlaneE2X,
10204                          pSigCorVsOsPlaneE2T,numOsE2,numOsE2X,numOsE2T,
10205                          sXTitle);
10206 
10207   //normalise the prof
10208   for (vector<TProfile*>::iterator profN=pSigCorVsDistN.begin();
10209        profN!=pSigCorVsDistN.end();++profN){
10210     static vector<Float_t>::iterator av=bigAv.begin();
10211     static vector<Int_t>::iterator count=bigAvCounter.begin();
10212     static vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
10213     
10214     //normalise the prof and scale the axes
10215     MSG("CDAnalysis",Msg::kDebug)
10216       <<"bigCounter="<<*count<<", bigAv="<<*av<<endl;
10217     if (*av>0) (*profN)->Scale((*count)/(*av));
10218     (*profN)->SetMaximum(1.2);
10219     (*profN)->SetMinimum(0.8);      
10220     (*profN)->SetTitle("Normalised Av. SigCor in Sliding Window");
10221     (*profN)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
10222     (*profN)->GetYaxis()->SetTitle("Normalised Av. SigCor");
10223     (*profN)->GetXaxis()->CenterTitle();
10224     (*profN)->GetYaxis()->CenterTitle();
10225     fS=(*profN)->GetName();
10226     Int_t pos=fS.find("14");
10227     //get the gradient for the chosen track-window
10228     if (pos>=0){
10229       (*profN)->Fit("pol1","q","",5,14);
10230       fSigCorVsDistM=(*profN)->GetFunction("pol1")->GetParameter(1);
10231       MSG("CDAnalysis",Msg::kDebug)<<"m="<<fSigCorVsDistM<<endl;
10232     }
10233 
10234     //now set the titles for the other one
10235     (*prof)->SetTitle("Average SigCor in Sliding Window");
10236     (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
10237     (*prof)->GetYaxis()->SetTitle("Average SigCor");
10238     (*prof)->GetXaxis()->CenterTitle();
10239     (*prof)->GetYaxis()->CenterTitle();
10240 
10241     av++;
10242     count++;
10243     prof++;
10244   }
10245 
10246   //normalise the pMeuVsLowEvLenCutNormN
10247   if (h14_16->GetMean()>0){
10248     pMeuVsLowEvLenCutNormN->Scale(1./h14_16->GetMean());
10249     pMeuVsLowEvLenCutNormN_1->Scale(1./h14_16->GetMean());
10250     pMeuVsUpEvLenCutNormN->Scale(1./h14_16->GetMean());
10251     pMeuVsUpEvLenCutNormN_1->Scale(1./h14_16->GetMean());
10252     pMeuVsStraightnessN->Scale(1./h14_16->GetMean());
10253   }
10254 
10255   Int_t lEvLenCutMin=-1;
10256   Int_t lEvLenCutMax=-1;
10257   this->GetEvLenMinMax(lEvLenCutMin,lEvLenCutMax);
10258   pMeuVsLowEvLenCutNormN->Fit
10259     ("pol1","q","",lEvLenCutMin,lEvLenCutMin+4);
10260   //<<"m="<<pMeuVsLowEvLenCutNormN->
10261   //GetFunction("pol1")->GetParameter(1)<<endl;
10262   fMeuVsEvLenCutM=pMeuVsLowEvLenCutNormN->
10263     GetFunction("pol1")->GetParameter(1);
10264 
10265   //create graphs
10266   TGraphErrors* gMeuVsWin=new TGraphErrors(6);
10267   TGraphErrors* gMeuVsWinCor=new TGraphErrors(6);
10268   TGraphErrors* gCorVsWin=new TGraphErrors(6);
10269   TGraphErrors* gMeuVsWinN=new TGraphErrors(6);
10270   TGraphErrors* gMeuVsWinCorN=new TGraphErrors(6);
10271   
10272   //MC correction factors relative to 14_16 MEU
10273   Float_t MCCor10_10=1.012;//0.988;
10274   Float_t MCCor10_16=1.007;//0.993;
10275   Float_t MCCor14_10=1.010;//0.990;
10276   Float_t MCCor14_16=1.0;//by definition
10277   Float_t MCCor18_10=1.007;//0.993;
10278   Float_t MCCor18_16=0.996;//1.004;
10279   
10280   gMeuVsWin->SetPoint(0,1,h10_10->GetMean());
10281   gMeuVsWin->SetPoint(1,2,h10_16->GetMean());
10282   gMeuVsWin->SetPoint(2,3,h14_10->GetMean());
10283   gMeuVsWin->SetPoint(3,4,h14_16->GetMean());
10284   gMeuVsWin->SetPoint(4,5,h18_10->GetMean());
10285   gMeuVsWin->SetPoint(5,6,h18_16->GetMean());
10286   
10287   gMeuVsWinCor->SetPoint(0,1,h10_10->GetMean()*MCCor10_10);
10288   gMeuVsWinCor->SetPoint(1,2,h10_16->GetMean()*MCCor10_16);
10289   gMeuVsWinCor->SetPoint(2,3,h14_10->GetMean()*MCCor14_10);
10290   gMeuVsWinCor->SetPoint(3,4,h14_16->GetMean()*MCCor14_16);
10291   gMeuVsWinCor->SetPoint(4,5,h18_10->GetMean()*MCCor18_10);
10292   gMeuVsWinCor->SetPoint(5,6,h18_16->GetMean()*MCCor18_16);
10293 
10294   vector<TGraph*> v(2);
10295   v[0]=dynamic_cast<TGraph*>(gMeuVsWin);
10296   v[1]=dynamic_cast<TGraph*>(gMeuVsWinCor);
10297   this->TGraphMinMax(v);
10298   
10299   gCorVsWin->SetPoint(0,1,1/MCCor10_10);
10300   gCorVsWin->SetPoint(1,2,1/MCCor10_16);
10301   gCorVsWin->SetPoint(2,3,1/MCCor14_10);
10302   gCorVsWin->SetPoint(3,4,1/MCCor14_16);
10303   gCorVsWin->SetPoint(4,5,1/MCCor18_10);
10304   gCorVsWin->SetPoint(5,6,1/MCCor18_16);
10305 
10306   Float_t av=(h10_10->GetMean()+h10_16->GetMean()+
10307               h14_10->GetMean()+h14_16->GetMean()+
10308               h18_10->GetMean()+h18_16->GetMean())/6;
10309   Float_t avC=(h10_10->GetMean()*MCCor10_10+
10310                h10_16->GetMean()*MCCor10_16+
10311                h14_10->GetMean()*MCCor14_10+
10312                h14_16->GetMean()*MCCor14_16+
10313                h18_10->GetMean()*MCCor18_10+
10314                h18_16->GetMean()*MCCor18_16)/6;
10315 
10316   if (av>0){
10317     gMeuVsWinN->SetPoint(0,1,h10_10->GetMean()/av);
10318     gMeuVsWinN->SetPoint(1,2,h10_16->GetMean()/av);
10319     gMeuVsWinN->SetPoint(2,3,h14_10->GetMean()/av);
10320     gMeuVsWinN->SetPoint(3,4,h14_16->GetMean()/av);
10321     gMeuVsWinN->SetPoint(4,5,h18_10->GetMean()/av);
10322     gMeuVsWinN->SetPoint(5,6,h18_16->GetMean()/av);
10323   }
10324   if (avC>0){
10325     gMeuVsWinCorN->SetPoint(0,1,h10_10->GetMean()*MCCor10_10/avC);
10326     gMeuVsWinCorN->SetPoint(1,2,h10_16->GetMean()*MCCor10_16/avC);
10327     gMeuVsWinCorN->SetPoint(2,3,h14_10->GetMean()*MCCor14_10/avC);
10328     gMeuVsWinCorN->SetPoint(3,4,h14_16->GetMean()*MCCor14_16/avC);
10329     gMeuVsWinCorN->SetPoint(4,5,h18_10->GetMean()*MCCor18_10/avC);
10330     gMeuVsWinCorN->SetPoint(5,6,h18_16->GetMean()*MCCor18_16/avC);      
10331   }
10332   v[0]=dynamic_cast<TGraph*>(gMeuVsWinN);
10333   v[1]=dynamic_cast<TGraph*>(gMeuVsWinCorN);
10334   this->TGraphMinMax(v);
10335 
10336   //have to explicitly write graphs to file with a name
10337   if (fOutFile){
10338     gMeuVsWin->Write("gMeuVsWin");
10339     gMeuVsWinCor->Write("gMeuVsWinCor");
10340     gCorVsWin->Write("gCorVsWin");
10341     gMeuVsWinN->Write("gMeuVsWinN");
10342     gMeuVsWinCorN->Write("gMeuVsWinCorN");
10343   }
10344 
10345   //turn on the stats box printing
10346   gStyle->SetOptStat(111111);
10347 
10348   TCanvas *cMeu=new TCanvas("cMeu","Meu",0,0,1200,800);
10349   cMeu->SetFillColor(0);
10350   cMeu->Divide(3,3);
10351   cMeu->cd(1);
10352   h15_18->Draw();
10353   cMeu->cd(2);
10354   h10_16->Draw();
10355   cMeu->cd(3);
10356   h10_10->Draw();
10357   cMeu->cd(4);
10358   h14_16->Draw();
10359   cMeu->cd(5);
10360   h14_10->Draw();
10361   cMeu->cd(6);
10362   h18_16->Draw();
10363   cMeu->cd(7);
10364   h18_10->Draw();
10365 
10366   TCanvas *cEvLen=new TCanvas("cEvLen","EvLen",0,0,1200,800);
10367   cEvLen->SetFillColor(0);
10368   cEvLen->Divide(2,3);
10369   cEvLen->cd(1);
10370   hEvLenFe->Draw();
10371   cEvLen->cd(2);
10372   pSigCorVsRange->Draw();
10373   
10374   TCanvas *cStVsPl=new TCanvas("cStVsPl","StVsPl",0,0,1200,800);
10375   cStVsPl->SetFillColor(0);
10376   cStVsPl->Divide(2,2);
10377   cStVsPl->cd(1);
10378   pStVsPl1->Draw("colz");
10379   cStVsPl->cd(3);
10380   pStVsPl2->Draw("colz");
10381   cStVsPl->cd(2);
10382   hStVsPl1->Draw("colz");
10383   cStVsPl->cd(4);
10384   hStVsPl2->Draw("colz");
10385 
10386   //find the peaks
10387   //this is really not a precise thing!!!
10388   //the resolution of simple "average of x planes" is only ~4% 
10389   //this can't be used to say anything about the beam energy
10390   //because every plane you add can pull the average about dramatically
10391   //a much more sophisticated technique is probably required
10392   fPeakPlaneSigCors=0;
10393   fPeakLastPlane=0;
10394   multimap<Int_t,Int_t> evLen;//plane,num
10395   for (Int_t i=0;i<60;i++){
10396     Float_t num=hEvLenFe->GetBinContent(i+1);
10397     //add to map
10398     evLen.insert(pair<Int_t,Int_t>(static_cast<Int_t>(num),i));
10399     MSG("CDAnalysis",Msg::kDebug)
10400       <<"plane="<<i<<", num="<<num
10401       <<", sigcor="<<pSigCorVsRange->GetBinContent(i+1)<<endl;
10402     static Float_t peakNum=0;
10403     if (num>peakNum){
10404       peakNum=num;
10405       fPeakLastPlane=i;
10406       fPeakPlaneSigCors=pSigCorVsRange->GetBinContent(i+1);
10407     }
10408   }
10409   /*give up, no useful info can be deduced
10410   multimap<Int_t,Int_t>::iterator evit=evLen.end();
10411   for (Int_t i=0;i<5;i++){
10412     evit--;
10413     static Float_t totNum=0;
10414     static Float_t avPl=0;
10415     Float_t pl=evit->second;
10416     Float_t oldNum=totNum;
10417     Float_t newNum=evit->first;
10418     totNum+=newNum;
10419     avPl=avPl*(oldNum/totNum)+pl*(newNum/totNum);//weighted av
10420     MSG("CDAnalysis",Msg::kDebug)
10421       <<"pl="<<pl<<", newNum="<<newNum<<", avPl="<<avPl<<endl;
10422     //evit--;
10423   }
10424   */
10425 
10426   MSG("CDAnalysis",Msg::kInfo) 
10427     <<"fPeakLastPlanePeak="<<fPeakLastPlane
10428     <<", fPeakPlaneSigCors="<<fPeakPlaneSigCors<<endl;
10429 
10430   if (sum15_18Counter!=0){
10431     MSG("CDAnalysis",Msg::kInfo) 
10432       <<endl
10433       <<" ** Calibration Summary **"<<endl
10434       <<"SigCor in sliding window 15_18:"<<endl
10435       <<"    SigCor dep="<<sum15_18<<" (N="<<sum15_18Counter<<")"<<endl
10436       <<"    Av SigCor dep="<<sum15_18/sum15_18Counter
10437       <<" +/- "<<100*(h15_18->GetRMS()/sqrt(h15_18->GetEntries()))/
10438       h15_18->GetMean()<<"%"<<endl
10439       <<"    Av SigCor dep per plane="<<(sum15_18/sum15_18Counter)/15
10440       <<" +/- "<<100*(h15_18->GetRMS()/sqrt(h15_18->GetEntries()))/
10441       h15_18->GetMean()<<"%"<<endl
10442       <<"MIPs in sliding window 15_18:"<<endl
10443       <<"    MIPs dep="<<sum15_18Mip
10444       <<" (N="<<sum15_18MipCounter<<")"<<endl
10445       <<"    Av MIPs dep="<<sum15_18Mip/sum15_18MipCounter
10446       <<endl;
10447     if (sumSigCorTotalCounter!=0){
10448       MSG("CDAnalysis",Msg::kInfo) 
10449         <<"SigCor of whole event:"<<endl
10450         <<"    Sum of SigCor dep="<<sumSigCorTotal
10451         <<" (N="<<sumSigCorTotalCounter<<")"<<endl
10452         <<"    Av sigCor dep="
10453         <<sumSigCorTotal/sumSigCorTotalCounter<<endl
10454         <<"    1 sigCor="
10455         <<1800/(sumSigCorTotal/sumSigCorTotalCounter)<<" MeV"
10456         <<endl;
10457     }
10458     if (sumMipTotalCounter!=0){
10459       MSG("CDAnalysis",Msg::kInfo) 
10460         <<"MIPs of whole event:"<<endl
10461         <<"    Sum of MIPs dep="<<sumMipTotal
10462         <<" (N="<<sumMipTotalCounter<<")"<<endl
10463         <<"    Av MIPs dep="
10464         <<sumMipTotal/sumMipTotalCounter<<endl
10465         <<"    1 MIP="
10466         <<1800/(sumMipTotal/sumMipTotalCounter)<<" MeV"<<endl
10467         <<"    1 GeV="
10468         <<(sumMipTotal/sumMipTotalCounter)/1.8<<" MIPs"
10469         <<endl<<endl;
10470     }
10471   }
10472 
10473   if (hMeuPLCor->GetEntries()>0){
10474     Double_t quantile=0.5;//quantile to compute
10475     Double_t median=-1;
10476     hMeuPLCor->GetQuantiles(1,&median,&quantile);
10477 
10478     Float_t meuPLCor=median;
10479     Float_t meuPLCorErr=hMeuPLCor->GetRMS()/
10480       sqrt(hMeuPLCor->GetEntries());
10481     Float_t meuPLCorErrRel=meuPLCorErr/meuPLCor;
10482     
10483     MSG("CDAnalysis",Msg::kInfo) 
10484       <<endl
10485       <<" ** New MEU (Median) Calibration Summary **"<<endl
10486       <<"SigCor in sliding window 14_16:"<<endl
10487       <<"    SigCors/MEU="<<meuPLCor
10488       <<" +/- "<<meuPLCorErr<<" ("<<100*meuPLCorErrRel<<"%)"<<endl
10489       <<endl;
10490   }
10491 
10492   string percentStraight="fpe";
10493   if (NCutsCounter>0){
10494     percentStraight=Form("%.1f",100.*straightTrackCounter/
10495                          NCutsCounter);
10496   }
10497   MSG("CDAnalysis",Msg::kInfo) 
10498     <<"PassPidCounter="<<passPidCounter<<endl
10499     <<"NCutsCounter="<<NCutsCounter<<endl
10500     <<"StraightTrackCounter="<<straightTrackCounter
10501     <<" ("<<percentStraight<<"% of NCuts)"<<endl;
10502 
10503   if (ts.GetSec()>minRunTime){
10504     //print the stats
10505     this->PrintPIDStats();
10506   }
10507 
10508   MSG("CDAnalysis",Msg::kInfo) 
10509     <<" ** Finished StoppingMuonCalibration method **"<<endl;
10510 }
10511 
10512 //......................................................................
10513 
10514 void CDAnalysis::MuonCalorimetry()
10515 {
10516   MSG("CDAnalysis",Msg::kInfo) 
10517     <<" ** Running MuonCalorimetry method... **"<<endl;
10518 
10519   //open the output file for the histograms
10520   fOutFile=this->OpenFile(fRunNumber,"MuonCal");
10521 
10522   TH1F *hSigCorTotal=new TH1F("hSigCorTotal","hSigCorTotal",1000,-2,75);
10523   hSigCorTotal->GetXaxis()->SetTitle("SigCors");
10524   hSigCorTotal->GetXaxis()->CenterTitle();
10525   hSigCorTotal->GetYaxis()->SetTitle("");
10526   hSigCorTotal->GetYaxis()->CenterTitle();
10527   hSigCorTotal->SetFillColor(0);
10528   hSigCorTotal->SetBit(TH1::kCanRebin);
10529 
10530   TH1F *hSigCorTotalTight=new TH1F("hSigCorTotalTight",
10531                                    "hSigCorTotalTight",1000,-2,75);
10532   hSigCorTotalTight->GetXaxis()->SetTitle("SigCors");
10533   hSigCorTotalTight->GetXaxis()->CenterTitle();
10534   hSigCorTotalTight->GetYaxis()->SetTitle("");
10535   hSigCorTotalTight->GetYaxis()->CenterTitle();
10536   hSigCorTotalTight->SetFillColor(0);
10537   hSigCorTotalTight->SetBit(TH1::kCanRebin);
10538 
10539   TH1F *hSigCorTotalPeak=new TH1F("hSigCorTotalPeak",
10540                                   "hSigCorTotalPeak",1000,-2,75);
10541   hSigCorTotalPeak->GetXaxis()->SetTitle("SigCors");
10542   hSigCorTotalPeak->GetXaxis()->CenterTitle();
10543   hSigCorTotalPeak->GetYaxis()->SetTitle("");
10544   hSigCorTotalPeak->GetYaxis()->CenterTitle();
10545   hSigCorTotalPeak->SetFillColor(0);
10546   hSigCorTotalPeak->SetBit(TH1::kCanRebin);
10547 
10548   TH1F *hEventLength=new TH1F("hEventLength","hEventLength hit",
10549                               77,-2,75);
10550   hEventLength->GetXaxis()->SetTitle("Event Length (planes)");
10551   hEventLength->GetXaxis()->CenterTitle();
10552   hEventLength->GetYaxis()->SetTitle("");
10553   hEventLength->GetYaxis()->CenterTitle();
10554   hEventLength->SetFillColor(0);
10555   hEventLength->SetBit(TH1::kCanRebin);
10556 
10557   TH1F *hEventLength2=new TH1F("hEventLength2","hEventLength",77,-2,75);
10558   hEventLength2->GetXaxis()->SetTitle("Event Length (planes)");
10559   hEventLength2->GetXaxis()->CenterTitle();
10560   hEventLength2->GetYaxis()->SetTitle("");
10561   hEventLength2->GetYaxis()->CenterTitle();
10562   hEventLength2->SetFillColor(0);
10563   hEventLength2->SetBit(TH1::kCanRebin);
10564 
10565   TH1F *hEventLength3=new TH1F("hEventLength3","hEventLength",77,-2,75);
10566   hEventLength3->SetTitle("Event Track Length");
10567   hEventLength3->GetXaxis()->SetTitle("Event Length (planes)");
10568   hEventLength3->GetXaxis()->CenterTitle();
10569   hEventLength3->GetYaxis()->SetTitle("");
10570   hEventLength3->GetYaxis()->CenterTitle();
10571   hEventLength3->SetFillColor(0);
10572   hEventLength3->SetBit(TH1::kCanRebin);
10573 
10574   TH1F *hMainEn=new TH1F("hMainEn","hMainEn",2000,-1,2);
10575   hMainEn->GetXaxis()->SetTitle("Beam Energy");
10576   hMainEn->GetXaxis()->CenterTitle();
10577   hMainEn->GetYaxis()->SetTitle("");
10578   hMainEn->GetYaxis()->CenterTitle();
10579   hMainEn->SetFillColor(0);
10580   hMainEn->SetBit(TH1::kCanRebin);
10581 
10582   TProfile* pEnVsRange=new TProfile("pEnVsRange","pEnVsRange",
10583                                     62,0,62);
10584   pEnVsRange->SetTitle
10585     ("Beam Energy from Calorimetry vs Range");
10586   pEnVsRange->GetXaxis()->SetTitle("Range (planes)");
10587   pEnVsRange->GetXaxis()->CenterTitle();
10588   pEnVsRange->GetYaxis()->SetTitle("Beam Energy");
10589   pEnVsRange->GetYaxis()->CenterTitle();
10590   pEnVsRange->SetFillColor(0);
10591 
10595   
10596   this->InitialiseLoopVariables();  
10597   
10598   for(Int_t event=0;event<fEvents;event++){
10599     
10600     this->SetLoopVariables(event);
10601 
10602     if (this->CutOnDeadChips()) continue;
10603     if (this->CutOnPid()) continue;
10604 
10605     Double_t sigCorTotal=0;
10606 
10607     //get the main particle energy
10608     hMainEn->Fill(this->GetMainParticleEnergy());
10609 
10610     //get tclones arrays for this snarl
10611     TClonesArray &cTrk=*fTrkHitInfo;
10612     Int_t numTrkHits=fTrkHitInfo->GetEntries();
10613     TClonesArray &cUnTrk = *fUnTrkHitInfo;
10614     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
10615     //CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
10616     TClonesArray &cXTalk = *fXTalkHits;
10617     Int_t numXTalkHits=fXTalkHits->GetEntries();
10618     //TClonesArray &cTruth = *fTruthHitInfo;
10619     Int_t numTruthHits=0;
10620     if (fTruthHitInfo) numTruthHits=fTruthHitInfo->GetEntries();
10621 
10623     //loop over the untracked hits in the snarl
10625     for (Int_t hit=0;hit<numUnTrkHits;hit++){
10626       //cast the tclonesarray up to a trackedhitinfo object
10627       CDTrackedHitInfo *hitInfo=
10628         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
10629 
10630       this->ReadInHitInfo(hitInfo);
10631 
10632       //cut out the bad channels
10633       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
10634 
10635       //check the channel's sanity
10636       this->StandardSanityChecks();
10637 
10638       if (fPlane==0) continue;
10639       //sum the sigcor in the event
10640       //make up for no plane 0 with 2 times plane 1
10641       else if (fPlane==1) sigCorTotal+=2*fChargeSigCor;
10642       else sigCorTotal+=fChargeSigCor;
10643     }
10644 
10646     //loop over xtalk hits in the snarl
10648     for (Int_t hit=0;hit<numXTalkHits;hit++){
10649       CDXTalkHitInfo *hitInfo=
10650         dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
10651 
10652       this->ReadInHitInfo(hitInfo);
10653       
10654       //cut out the bad channels
10655       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
10656 
10657       //check the channel's sanity
10658       this->StandardSanityChecks();
10659 
10660       if (fPlane==0) continue;
10661       //sum the sigcor in the event
10662       //make up for no plane 0 with 2 times plane 1
10663       else if (fPlane==1) sigCorTotal+=2*fChargeSigCor;
10664       else sigCorTotal+=fChargeSigCor;
10665     }
10666 
10668     //loop over the tracked hits
10670     for (Int_t hit=0;hit<numTrkHits;hit++){
10671       CDTrackedHitInfo *trackedHitInfo=
10672         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
10673           
10674       this->ReadInHitInfo(trackedHitInfo);
10675 
10676       //cut out the bad channels
10677       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
10678 
10679       //check the channel's sanity
10680       this->StandardSanityChecks();
10681 
10682       //calculate the first and last planes
10683       this->CalcFirstLastPlane(fPlane);
10684 
10685       if (fPlane==0) continue;
10686       //sum the sigcor in the event
10687       //make up for no plane 0 with 2 times plane 1
10688       else if (fPlane==1) sigCorTotal+=2*fChargeSigCor;
10689       else sigCorTotal+=fChargeSigCor;
10690     }
10692     //end of loop over the tracked hits
10694 
10695     hEventLength->Fill(fLastPlane+1);
10696 
10697     //make sure that the first plane makes sense and was actually set
10698     if (fFirstPlane<0 || fFirstPlane>59) continue;
10699 
10700     //calculate the event energy
10701     Double_t eventEn=(fScEnDepPerMEU/fSigCorPerMEU)*sigCorTotal*
10702       (1/fRatioScEnToBeamEn);
10703     //calc the last plane on the track with no xtalk
10704     Int_t lastPlaneNoXTalk=this->CalcLastPlaneOnTrkNoXTalk();
10705     hEventLength3->Fill(lastPlaneNoXTalk+1);
10706 
10707     //fill the prof
10708     pEnVsRange->Fill(lastPlaneNoXTalk+1,eventEn);
10709 
10710     //make event length cuts
10711     if (this->CutOnEventLength()) continue;
10712     //make track quality cuts
10713     if (this->CutOnTrackQuality()) continue;
10714 
10715     //fill the total sigcor histo
10716     hSigCorTotal->Fill(sigCorTotal);
10717 
10718     //fill event length plots for those passing cuts
10719     hEventLength2->Fill(fLastPlane+1);
10720 
10721     //look at a certain part of the spectrum
10722     if (lastPlaneNoXTalk+1>=50 && lastPlaneNoXTalk+1<53){//50,51,52
10723       //fill the total sigcor histo
10724       hSigCorTotalTight->Fill(sigCorTotal);
10725     }
10726     
10727     if (lastPlaneNoXTalk+1==51){
10728       //fill the total sigcor histo
10729       hSigCorTotalPeak->Fill(sigCorTotal);
10730     }
10731   }//end of for                                       
10732   
10736 
10737   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
10738 
10739   //turn off the stats box printing
10740   gStyle->SetOptStat(0);
10741 
10742 
10743   //turn off the stats box printing
10744   //gStyle->SetOptStat(0);
10745   gStyle->SetOptStat(1111111);
10746 
10747   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
10748   cGeom->SetFillColor(0);
10749   cGeom->Divide(2,2);
10750   cGeom->cd(1);
10751   hEventLength->Draw();
10752   cGeom->cd(2);
10753   hEventLength2->Draw();
10754   cGeom->cd(3);
10755   hEventLength3->Draw();
10756   cGeom->cd(3);
10757 
10758   TCanvas *cEnVsRange=new TCanvas("cEnVsRange","EnVsRange",
10759                                   0,0,1200,800);
10760   cEnVsRange->SetFillColor(0);
10761   cEnVsRange->Divide(1,2);
10762   cEnVsRange->cd(1);
10763   pEnVsRange->Draw();
10764   cEnVsRange->cd(2);
10765   hEventLength3->Draw();
10766 
10767   TCanvas *cSigCor=new TCanvas("cSigCor","SigCor",0,0,1200,800);
10768   cSigCor->SetFillColor(0);
10769   cSigCor->Divide(2,2);
10770   cSigCor->cd(1);
10771   hSigCorTotal->Draw();
10772   cSigCor->cd(2);
10773   hSigCorTotalTight->Draw();
10774   cSigCor->cd(3);
10775   hSigCorTotalPeak->Draw();
10776   cSigCor->cd(4);
10777   hMainEn->Draw();
10778 
10779   MSG("CDAnalysis",Msg::kInfo) 
10780     <<endl
10781     <<"Mean sigCorTotal="<<hSigCorTotal->GetMean()<<endl
10782     <<"Ratio ScEn to BeamEn="<<fRatioScEnToBeamEn
10783     <<" ("<<1/fRatioScEnToBeamEn<<")"<<endl
10784     <<"GeV per SigCor="<<fScEnDepPerMEU/fSigCorPerMEU<<endl
10785     <<"Beam energy from Calorimetry (lose)="
10786     <<((fScEnDepPerMEU/fSigCorPerMEU)*
10787     hSigCorTotal->GetMean()*(1/fRatioScEnToBeamEn))/
10788     Munits::gigaelectronvolt<<" "<<Munits::base_energy_name<<endl
10789     <<"Beam energy from Calorimetry (tight)="
10790     <<((fScEnDepPerMEU/fSigCorPerMEU)*
10791     hSigCorTotalTight->GetMean()*(1/fRatioScEnToBeamEn))/
10792     Munits::gigaelectronvolt<<" "<<Munits::base_energy_name<<endl
10793     <<"Beam energy from Calorimetry (peak)="
10794     <<((fScEnDepPerMEU/fSigCorPerMEU)*
10795     hSigCorTotalPeak->GetMean()*(1/fRatioScEnToBeamEn))/
10796     Munits::gigaelectronvolt<<" "<<Munits::base_energy_name<<endl<<endl;
10797 
10798   MSG("CDAnalysis",Msg::kInfo) 
10799     <<" ** Finished MuonCalorimetry method **"<<endl;
10800 }
10801 
10802 //......................................................................
10803 
10804 void CDAnalysis::MuonSampleCuts()
10805 {
10806   MSG("CDAnalysis",Msg::kInfo) 
10807     <<" ** Running MuonSampleCuts method... **"<<endl;
10808 
10809   //open the output file for the histograms
10810   //fOutFile=this->OpenFile(fRunNumber,"MuonSampleCuts");
10811 
10812   TH1F *hNumPlanesAll=new TH1F("hNumPlanesAll","NumPlanesAll hit",
10813                                77,-2,75);
10814   hNumPlanesAll->SetTitle("Number of Planes Hit");
10815   hNumPlanesAll->GetXaxis()->SetTitle("Number of Planes Hit");
10816   hNumPlanesAll->GetXaxis()->CenterTitle();
10817   hNumPlanesAll->GetYaxis()->SetTitle("");
10818   hNumPlanesAll->GetYaxis()->CenterTitle();
10819   hNumPlanesAll->SetFillColor(0);
10820   hNumPlanesAll->SetBit(TH1::kCanRebin);
10821 
10822   TH1F *hNumPlanesN_Qual=new TH1F("hNumPlanesN_Qual",
10823                                   "hNumPlanesN_Qual",
10824                                   77,-2,75);
10825   hNumPlanesN_Qual->SetTitle("Number of Planes Hit");
10826   hNumPlanesN_Qual->GetXaxis()->SetTitle("Number of Planes Hit");
10827   hNumPlanesN_Qual->GetXaxis()->CenterTitle();
10828   hNumPlanesN_Qual->GetYaxis()->SetTitle("");
10829   hNumPlanesN_Qual->GetYaxis()->CenterTitle();
10830   hNumPlanesN_Qual->SetFillColor(0);
10831   hNumPlanesN_Qual->SetLineColor(2);
10832   hNumPlanesN_Qual->SetBit(TH1::kCanRebin);
10833 
10834   TH1F *hNumPlanesN=new TH1F("hNumPlanesN",
10835                                   "hNumPlanesN",
10836                                   77,-2,75);
10837   hNumPlanesN->SetTitle("Number of Planes Hit");
10838   hNumPlanesN->GetXaxis()->SetTitle("Number of Planes Hit");
10839   hNumPlanesN->GetXaxis()->CenterTitle();
10840   hNumPlanesN->GetYaxis()->SetTitle("");
10841   hNumPlanesN->GetYaxis()->CenterTitle();
10842   hNumPlanesN->SetFillColor(0);
10843   hNumPlanesN->SetLineColor(3);
10844   hNumPlanesN->SetBit(TH1::kCanRebin);
10845 
10846   TH1F *hEventLength=new TH1F("hEventLength","hEventLength hit",
10847                               77,-2,75);
10848   hEventLength->GetXaxis()->SetTitle("Event Length (planes)");
10849   hEventLength->GetXaxis()->CenterTitle();
10850   hEventLength->GetYaxis()->SetTitle("");
10851   hEventLength->GetYaxis()->CenterTitle();
10852   hEventLength->SetFillColor(0);
10853   hEventLength->SetBit(TH1::kCanRebin);
10854 
10855   TH1F *hEventLength2=new TH1F("hEventLength2","hEventLength",77,-2,75);
10856   hEventLength2->GetXaxis()->SetTitle("Event Length (planes)");
10857   hEventLength2->GetXaxis()->CenterTitle();
10858   hEventLength2->GetYaxis()->SetTitle("");
10859   hEventLength2->GetYaxis()->CenterTitle();
10860   hEventLength2->SetFillColor(0);
10861   hEventLength2->SetBit(TH1::kCanRebin);
10862 
10863   TH1F *hEventLength3=new TH1F("hEventLength3","hEventLength",77,-2,75);
10864   hEventLength3->SetTitle("Event Track Length");
10865   hEventLength3->GetXaxis()->SetTitle("Event Length (planes)");
10866   hEventLength3->GetXaxis()->CenterTitle();
10867   hEventLength3->GetYaxis()->SetTitle("");
10868   hEventLength3->GetYaxis()->CenterTitle();
10869   hEventLength3->SetFillColor(0);
10870   hEventLength3->SetBit(TH1::kCanRebin);
10871 
10872   TProfile* pMeuVsEvLenCut=new TProfile("pMeuVsEvLenCut",
10873                                         "pMeuVsEvLenCut",
10874                                         62,0,62);
10875   pMeuVsEvLenCut->SetTitle("MEU Number vs Event Length Cut");
10876   pMeuVsEvLenCut->GetXaxis()->SetTitle("Lower Event Length Cut");
10877   pMeuVsEvLenCut->GetXaxis()->CenterTitle();
10878   pMeuVsEvLenCut->GetYaxis()->SetTitle("SigCors per MEU");
10879   pMeuVsEvLenCut->GetYaxis()->CenterTitle();
10880   pMeuVsEvLenCut->SetFillColor(0);
10881 
10885   
10886   this->InitialiseLoopVariables();  
10887   
10888   for(Int_t event=0;event<fEvents;event++){
10889     
10890     this->SetLoopVariables(event);
10891 
10892     if (this->CutOnDeadChips()) continue;
10893     if (this->CutOnPid()) continue;
10894 
10895     map<Int_t,Float_t> planeSigCorT;
10896     map<Int_t,Int_t> numPlanesHitAll;
10897 
10898     //get tclones arrays for this snarl
10899     TClonesArray &cTrk=*fTrkHitInfo;
10900     Int_t numTrkHits=fTrkHitInfo->GetEntries();
10901     TClonesArray &cUnTrk = *fUnTrkHitInfo;
10902     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
10903     //CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
10904     TClonesArray &cXTalk = *fXTalkHits;
10905     Int_t numXTalkHits=fXTalkHits->GetEntries();
10906 
10908     //loop over the untracked hits in the snarl
10910     for (Int_t hit=0;hit<numUnTrkHits;hit++){
10911       //cast the tclonesarray up to a trackedhitinfo object
10912       CDTrackedHitInfo *hitInfo=
10913         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
10914 
10915       this->ReadInHitInfo(hitInfo);
10916 
10917       //cut out the bad channels
10918       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
10919 
10920       //check the channel's sanity
10921       this->StandardSanityChecks();
10922 
10923       //count the number of planes hit
10924       numPlanesHitAll[fPlane]++;
10925 
10926       if (fPlane==0) continue;
10927       //add up the total sigcor per plane
10928       planeSigCorT[fPlane]+=fChargeSigCor;
10929     }
10930 
10932     //loop over xtalk hits in the snarl
10934     for (Int_t hit=0;hit<numXTalkHits;hit++){
10935       CDXTalkHitInfo *hitInfo=
10936         dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
10937 
10938       this->ReadInHitInfo(hitInfo);
10939       
10940       //cut out the bad channels
10941       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
10942 
10943       //check the channel's sanity
10944       this->StandardSanityChecks();
10945 
10946       //count the number of planes hit
10947       numPlanesHitAll[fPlane]++;
10948 
10949       if (fPlane==0) continue;
10950       //add up the total sigcor per plane
10951       planeSigCorT[fPlane]+=fChargeSigCor;
10952     }
10953 
10955     //loop over the tracked hits
10957     for (Int_t hit=0;hit<numTrkHits;hit++){
10958       CDTrackedHitInfo *trackedHitInfo=
10959         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
10960           
10961       this->ReadInHitInfo(trackedHitInfo);
10962 
10963       //cut out the bad channels
10964       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
10965 
10966       //check the channel's sanity
10967       this->StandardSanityChecks();
10968 
10969       //calculate the first and last planes
10970       this->CalcFirstLastPlane(fPlane);
10971 
10972       //count the number of planes hit
10973       numPlanesHitAll[fPlane]++;
10974 
10975       if (fPlane==0) continue;
10976       //add up the total sigcor per plane
10977       planeSigCorT[fPlane]+=fChargeSigCor;
10978     }
10980     //end of loop over the tracked hits
10982 
10983     hEventLength->Fill(fLastPlane+1);
10984     hNumPlanesAll->Fill(numPlanesHitAll.size());
10985 
10986     //make sure that the first plane makes sense and was actually set
10987     if (fFirstPlane<0 || fFirstPlane>59) continue;
10988 
10989     //do nasty hack for plane 40 - very nasty!!!!
10990     //if (fRunNumber==70709 || fRunNumber==70705){
10991     //planeSigCorT[40]=planeSigCorT[38];
10992     //}
10993 
10994     hNumPlanesN_Qual->Fill(numPlanesHitAll.size());
10995 
10996     //make event length cuts
10997     //if (this->CutOnEventLength()) continue;
10998     //make track quality cuts
10999     //if (this->CutOnTrackQuality()) continue;
11000 
11001     hNumPlanesN->Fill(numPlanesHitAll.size());
11002 
11003     //fill event length plots for those passing cuts
11004     hEventLength2->Fill(fLastPlane+1);
11005 
11007     //section for 15_18 window
11009     Int_t minEventLength=15+18+1;//+1 because don't want plane zero
11010     Int_t maxEvLen=57;//cut out muons ending in pl 58 or 59
11011     if (fLastPlane<minEventLength || fLastPlane>maxEvLen) continue;
11012 
11013     Float_t localSum15_18=0;
11014     Float_t localSum15_18Counter=0;
11015 
11016     Int_t windowStart=fLastPlane-18;
11017     Int_t windowSize=15;
11018     
11019     //loop through the hits in the window
11020     for (Int_t i=0;i<windowSize;i++){
11021       Int_t plane=windowStart-i;
11022       
11023       //calculate the best window value
11024       //if fLP=48 then the first plane included is 30
11025       //this is actually the 19th from the end of the track
11026       localSum15_18+=planeSigCorT[plane];//total including xtalk
11027       localSum15_18Counter++;
11028     }
11029 
11030     for (Int_t lowerPlCut=57;lowerPlCut>minEventLength;lowerPlCut--){
11031 
11032       if (localSum15_18Counter!=0 && fLastPlane>=lowerPlCut){
11033 
11034         MSG("CDAnalysis",Msg::kVerbose)
11035           <<"Filling prof: lowerPlCut="<<lowerPlCut
11036           <<", 15_18="<<localSum15_18/windowSize<<endl;
11037 
11038         pMeuVsEvLenCut->Fill(lowerPlCut,localSum15_18/windowSize);
11039       }
11040     }
11041 
11042   }//end of for                                       
11043   
11047 
11048   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
11049 
11050   //turn off the stats box printing
11051   gStyle->SetOptStat(0);
11052 
11053 
11054   //turn off the stats box printing
11055   //gStyle->SetOptStat(0);
11056   gStyle->SetOptStat(1111111);
11057 
11058   TCanvas *cGeom=new TCanvas("cGeom","cGeom",0,0,1200,800);
11059   cGeom->SetFillColor(0);
11060   cGeom->Divide(2,2);
11061   cGeom->cd(1);
11062   hEventLength->Draw();
11063   cGeom->cd(2);
11064   hEventLength2->Draw();
11065   cGeom->cd(3);
11066   hEventLength3->Draw();
11067   cGeom->cd(3);
11068 
11069   TCanvas *cNumPl=new TCanvas("cNumPl","cNumPl",0,0,1200,800);
11070   cNumPl->SetFillColor(0);
11071   cNumPl->Divide(2,2);
11072   cNumPl->cd(1);
11073   hNumPlanesAll->Draw();
11074   cNumPl->cd(2);
11075   hNumPlanesN_Qual->Draw();
11076   cNumPl->cd(3);
11077   hNumPlanesN->Draw();
11078   cNumPl->cd(4);
11079   hNumPlanesAll->Draw();
11080   hNumPlanesN_Qual->Draw("sames");
11081   hNumPlanesN->Draw("sames");
11082 
11083   TCanvas *cMeuVsEvLenCut=new TCanvas("cMeuVsEvLenCut",
11084                                       "cMeuVsEvLenCut",0,0,1200,800);
11085   cMeuVsEvLenCut->SetFillColor(0);
11086   //cMeuVsEvLenCut->Divide(1,1);
11087   //cMeuVsEvLenCut->cd(1);
11088   pMeuVsEvLenCut->Draw();
11089 
11090   MSG("CDAnalysis",Msg::kInfo) 
11091     <<" ** Finished MuonSampleCuts method **"<<endl;
11092 }
11093 
11094 //......................................................................
11095 
11096 void CDAnalysis::ElectronResponse()
11097 {
11098   MSG("CDAnalysis",Msg::kInfo) 
11099     <<" ** Running ElectronResponse method... **"<<endl;
11100 
11101   //open the output file for the histograms if not already done
11102   if (!fOutFile) fOutFile=this->OpenFile(fRunNumber,"ElecRes");
11103 
11104   TH1F *hNumPlanesAll_Elec=new TH1F("hNumPlanesAll_Elec",
11105                                     "NumPlanesAll_Elec hit",77,-2,75);
11106   hNumPlanesAll_Elec->GetXaxis()->SetTitle("Number of Planes Hit");
11107   hNumPlanesAll_Elec->GetXaxis()->CenterTitle();
11108   hNumPlanesAll_Elec->GetYaxis()->SetTitle("");
11109   hNumPlanesAll_Elec->GetYaxis()->CenterTitle();
11110   hNumPlanesAll_Elec->SetFillColor(0);
11111   hNumPlanesAll_Elec->SetBit(TH1::kCanRebin);
11112 
11113   TH1F *hNumPlanesAllN_Elec=new TH1F("hNumPlanesAllN_Elec",
11114                                     "NumPlanesAllN_Elec hit",77,-2,75);
11115   hNumPlanesAllN_Elec->GetXaxis()->SetTitle("Number of Planes Hit");
11116   hNumPlanesAllN_Elec->GetXaxis()->CenterTitle();
11117   hNumPlanesAllN_Elec->GetYaxis()->SetTitle("");
11118   hNumPlanesAllN_Elec->GetYaxis()->CenterTitle();
11119   hNumPlanesAllN_Elec->SetFillColor(0);
11120   hNumPlanesAllN_Elec->SetBit(TH1::kCanRebin);
11121   
11122   TH1F *hSumSigCor_Elec=new TH1F("hSumSigCor_Elec","hSumSigCor_Elec",
11123                                  500,-2,100000);
11124   hSumSigCor_Elec->SetTitle("Sum of Corrected ADCs in Event");
11125   hSumSigCor_Elec->GetXaxis()->
11126     SetTitle("Sum of Corrected ADCs in Event");
11127   hSumSigCor_Elec->GetXaxis()->CenterTitle();
11128   hSumSigCor_Elec->GetYaxis()->SetTitle("");
11129   hSumSigCor_Elec->GetYaxis()->CenterTitle();
11130   hSumSigCor_Elec->SetFillColor(0);
11131   //hSumSigCor_Elec->SetBit(TH1::kCanRebin);
11132 
11133   TH1F *hSumMeu_Elec=new TH1F("hSumMeu_Elec","hSumMeu_Elec",500,-2,400);
11134   hSumMeu_Elec->SetTitle("Sum of MEUs in Event");
11135   hSumMeu_Elec->GetXaxis()->SetTitle("Sum of MEUs in Event");
11136   hSumMeu_Elec->GetXaxis()->CenterTitle();
11137   hSumMeu_Elec->GetYaxis()->SetTitle("");
11138   hSumMeu_Elec->GetYaxis()->CenterTitle();
11139   hSumMeu_Elec->SetFillColor(0);
11140   //hSumMeu_Elec->SetBit(TH1::kCanRebin);
11141 
11142   TH1F *hSumMip_Elec=new TH1F("hSumMip_Elec","hSumMip_Elec",500,-2,400);
11143   hSumMip_Elec->SetTitle("Sum of Cosmic-MIPs in Event");
11144   hSumMip_Elec->GetXaxis()->SetTitle("Sum of Cosmic-MIPs in Event");
11145   hSumMip_Elec->GetXaxis()->CenterTitle();
11146   hSumMip_Elec->GetYaxis()->SetTitle("");
11147   hSumMip_Elec->GetYaxis()->CenterTitle();
11148   hSumMip_Elec->SetFillColor(0);
11149   //hSumMip_Elec->SetBit(TH1::kCanRebin);
11150 
11151   TH1F *hSigCor_Elec=new TH1F("hSigCor_Elec","hSigCor_Elec",
11152                               5000,-2,10000);
11153   hSigCor_Elec->SetTitle("Corrected ADCs");
11154   hSigCor_Elec->GetXaxis()->SetTitle("Corrected ADCs");
11155   hSigCor_Elec->GetXaxis()->CenterTitle();
11156   hSigCor_Elec->GetYaxis()->SetTitle("");
11157   hSigCor_Elec->GetYaxis()->CenterTitle();
11158   hSigCor_Elec->SetFillColor(0);
11159   hSigCor_Elec->SetBit(TH1::kCanRebin);
11160 
11161   TH1F *hOLChi2_Elec=new TH1F("hOLChi2_Elec","hOLChi2_Elec",
11162                                200,0,10);
11163   hOLChi2_Elec->GetXaxis()->SetTitle("OLChi2");
11164   hOLChi2_Elec->GetXaxis()->CenterTitle();
11165   hOLChi2_Elec->GetYaxis()->SetTitle("");
11166   hOLChi2_Elec->GetYaxis()->CenterTitle();
11167   hOLChi2_Elec->SetFillColor(0);
11168   hOLChi2_Elec->SetLineWidth(3);
11169   //hOLChi2_Elec->SetBit(TH1::kCanRebin);
11170   
11171   TH1F *hOLChi2_ElecN_1=new TH1F("hOLChi2_ElecN_1","hOLChi2_ElecN_1",
11172                                200,0,10);
11173   hOLChi2_ElecN_1->GetXaxis()->SetTitle("OLChi2");
11174   hOLChi2_ElecN_1->GetXaxis()->CenterTitle();
11175   hOLChi2_ElecN_1->GetYaxis()->SetTitle("");
11176   hOLChi2_ElecN_1->GetYaxis()->CenterTitle();
11177   hOLChi2_ElecN_1->SetFillColor(0);
11178   hOLChi2_ElecN_1->SetLineWidth(3);
11179   hOLChi2_ElecN_1->SetLineColor(2);
11180   //hOLChi2_ElecN_1->SetBit(TH1::kCanRebin);
11181 
11182   TH1F *hOLChi2_ElecN=new TH1F("hOLChi2_ElecN","hOLChi2_ElecN",
11183                                200,0,10);
11184   hOLChi2_ElecN->GetXaxis()->SetTitle("OLChi2");
11185   hOLChi2_ElecN->GetXaxis()->CenterTitle();
11186   hOLChi2_ElecN->GetYaxis()->SetTitle("");
11187   hOLChi2_ElecN->GetYaxis()->CenterTitle();
11188   hOLChi2_ElecN->SetFillColor(0);
11189   hOLChi2_ElecN->SetLineWidth(3);
11190   hOLChi2_ElecN->SetLineColor(4);
11191   //hOLChi2_ElecN->SetBit(TH1::kCanRebin);
11192 
11193   TH1F *hKovADC1_Elec=new TH1F("hKovADC1_Elec","KovADC1_Elec",
11194                                400,-5,10000);
11195   hKovADC1_Elec->GetXaxis()->SetTitle("KovADC1");
11196   hKovADC1_Elec->GetXaxis()->CenterTitle();
11197   hKovADC1_Elec->GetYaxis()->SetTitle("");
11198   hKovADC1_Elec->GetYaxis()->CenterTitle();
11199   hKovADC1_Elec->SetFillColor(0);
11200   hKovADC1_Elec->SetBit(TH1::kCanRebin);
11201 
11202   TH1F *hKovADC1_ElecN_1=new TH1F("hKovADC1_ElecN_1","KovADC1_ElecN_1",
11203                                 400,-5,10000);
11204   hKovADC1_ElecN_1->GetXaxis()->SetTitle("KovADC1");
11205   hKovADC1_ElecN_1->GetXaxis()->CenterTitle();
11206   hKovADC1_ElecN_1->GetYaxis()->SetTitle("");
11207   hKovADC1_ElecN_1->GetYaxis()->CenterTitle();
11208   hKovADC1_ElecN_1->SetFillColor(0);
11209   hKovADC1_ElecN_1->SetLineColor(2);
11210   hKovADC1_ElecN_1->SetBit(TH1::kCanRebin);
11211 
11212   TH1F *hKovADC1_ElecN=new TH1F("hKovADC1_ElecN","KovADC1_ElecN",
11213                                 400,-5,10000);
11214   hKovADC1_ElecN->GetXaxis()->SetTitle("KovADC1");
11215   hKovADC1_ElecN->GetXaxis()->CenterTitle();
11216   hKovADC1_ElecN->GetYaxis()->SetTitle("");
11217   hKovADC1_ElecN->GetYaxis()->CenterTitle();
11218   hKovADC1_ElecN->SetFillColor(0);
11219   hKovADC1_ElecN->SetLineColor(4);
11220   hKovADC1_ElecN->SetBit(TH1::kCanRebin);
11221 
11222   TH1F *hKovADC2_Elec=new TH1F("hKovADC2_Elec","KovADC2_Elec",
11223                                400,-5,10000);
11224   hKovADC2_Elec->GetXaxis()->SetTitle("KovADC2");
11225   hKovADC2_Elec->GetXaxis()->CenterTitle();
11226   hKovADC2_Elec->GetYaxis()->SetTitle("");
11227   hKovADC2_Elec->GetYaxis()->CenterTitle();
11228   hKovADC2_Elec->SetFillColor(0);
11229   hKovADC2_Elec->SetBit(TH1::kCanRebin);
11230 
11231   TH1F *hKovADC2_ElecN_1=new TH1F("hKovADC2_ElecN_1","KovADC2_ElecN_1",
11232                                 400,-5,10000);
11233   hKovADC2_ElecN_1->GetXaxis()->SetTitle("KovADC2");
11234   hKovADC2_ElecN_1->GetXaxis()->CenterTitle();
11235   hKovADC2_ElecN_1->GetYaxis()->SetTitle("");
11236   hKovADC2_ElecN_1->GetYaxis()->CenterTitle();
11237   hKovADC2_ElecN_1->SetFillColor(0);
11238   hKovADC2_ElecN_1->SetLineColor(2);
11239   hKovADC2_ElecN_1->SetBit(TH1::kCanRebin);
11240 
11241   TH1F *hKovADC2_ElecN=new TH1F("hKovADC2_ElecN","KovADC2_ElecN",
11242                                 400,-5,10000);
11243   hKovADC2_ElecN->GetXaxis()->SetTitle("KovADC2");
11244   hKovADC2_ElecN->GetXaxis()->CenterTitle();
11245   hKovADC2_ElecN->GetYaxis()->SetTitle("");
11246   hKovADC2_ElecN->GetYaxis()->CenterTitle();
11247   hKovADC2_ElecN->SetFillColor(0);
11248   hKovADC2_ElecN->SetLineColor(4);
11249   hKovADC2_ElecN->SetBit(TH1::kCanRebin);
11250 
11251   TH1F *hKovADC3_Elec=new TH1F("hKovADC3_Elec","KovADC3_Elec",
11252                                400,-5,10000);
11253   hKovADC3_Elec->GetXaxis()->SetTitle("KovADC3");
11254   hKovADC3_Elec->GetXaxis()->CenterTitle();
11255   hKovADC3_Elec->GetYaxis()->SetTitle("");
11256   hKovADC3_Elec->GetYaxis()->CenterTitle();
11257   hKovADC3_Elec->SetFillColor(0);
11258   hKovADC3_Elec->SetBit(TH1::kCanRebin);
11259 
11260   TH1F *hKovADC3_ElecN_1=new TH1F("hKovADC3_ElecN_1","KovADC3_ElecN_1",
11261                                 400,-5,10000);
11262   hKovADC3_ElecN_1->GetXaxis()->SetTitle("KovADC3");
11263   hKovADC3_ElecN_1->GetXaxis()->CenterTitle();
11264   hKovADC3_ElecN_1->GetYaxis()->SetTitle("");
11265   hKovADC3_ElecN_1->GetYaxis()->CenterTitle();
11266   hKovADC3_ElecN_1->SetFillColor(0);
11267   hKovADC3_ElecN_1->SetLineColor(2);
11268   hKovADC3_ElecN_1->SetBit(TH1::kCanRebin);
11269 
11270   TH1F *hKovADC3_ElecN=new TH1F("hKovADC3_ElecN","KovADC3_ElecN",
11271                                 400,-5,10000);
11272   hKovADC3_ElecN->GetXaxis()->SetTitle("KovADC3");
11273   hKovADC3_ElecN->GetXaxis()->CenterTitle();
11274   hKovADC3_ElecN->GetYaxis()->SetTitle("");
11275   hKovADC3_ElecN->GetYaxis()->CenterTitle();
11276   hKovADC3_ElecN->SetFillColor(0);
11277   hKovADC3_ElecN->SetLineColor(4);
11278   hKovADC3_ElecN->SetBit(TH1::kCanRebin);
11279 
11280   TH1F *hTofDiff_Elec=new TH1F("hTofDiff_Elec","hTofDiff_Elec",
11281                                400,-4000,4000);
11282   hTofDiff_Elec->GetXaxis()->SetTitle("TOF");
11283   hTofDiff_Elec->GetXaxis()->CenterTitle();
11284   hTofDiff_Elec->GetYaxis()->SetTitle("");
11285   hTofDiff_Elec->GetYaxis()->CenterTitle();
11286   hTofDiff_Elec->SetFillColor(0);
11287   hTofDiff_Elec->SetBit(TH1::kCanRebin);
11288 
11289   TH1F *hTofDiff_ElecN_1=new TH1F("hTofDiff_ElecN_1","hTofDiff_ElecN_1",
11290                                 400,-4000,4000);
11291   hTofDiff_ElecN_1->GetXaxis()->SetTitle("TOF");
11292   hTofDiff_ElecN_1->GetXaxis()->CenterTitle();
11293   hTofDiff_ElecN_1->GetYaxis()->SetTitle("");
11294   hTofDiff_ElecN_1->GetYaxis()->CenterTitle();
11295   hTofDiff_ElecN_1->SetFillColor(0);
11296   hTofDiff_ElecN_1->SetLineColor(2);
11297   hTofDiff_ElecN_1->SetBit(TH1::kCanRebin);
11298 
11299   TH1F *hTofDiff_ElecN=new TH1F("hTofDiff_ElecN","hTofDiff_ElecN",
11300                                 400,-4000,4000);
11301   hTofDiff_ElecN->GetXaxis()->SetTitle("TOF");
11302   hTofDiff_ElecN->GetXaxis()->CenterTitle();
11303   hTofDiff_ElecN->GetYaxis()->SetTitle("");
11304   hTofDiff_ElecN->GetYaxis()->CenterTitle();
11305   hTofDiff_ElecN->SetFillColor(0);
11306   hTofDiff_ElecN->SetLineColor(4);
11307   hTofDiff_ElecN->SetBit(TH1::kCanRebin);
11308 
11309   TH1F *hTofKov1Diff_Elec=new TH1F("hTofKov1Diff_Elec",
11310                                    "hTofKov1Diff_Elec",4000,-2,3);
11311   hTofKov1Diff_Elec->GetXaxis()->SetTitle("Tof-Ckv time");
11312   hTofKov1Diff_Elec->GetXaxis()->CenterTitle();
11313   hTofKov1Diff_Elec->GetYaxis()->SetTitle("");
11314   hTofKov1Diff_Elec->GetYaxis()->CenterTitle();
11315   hTofKov1Diff_Elec->SetFillColor(0);
11316   hTofKov1Diff_Elec->SetBit(TH1::kCanRebin);
11317 
11318   TH1F *hTofKov1DiffN_1_Elec=new TH1F("hTofKov1DiffN_1_Elec",
11319                                    "hTofKov1DiffN_1_Elec",4000,-2,3);
11320   hTofKov1DiffN_1_Elec->GetXaxis()->SetTitle("Tof-Ckv time");
11321   hTofKov1DiffN_1_Elec->GetXaxis()->CenterTitle();
11322   hTofKov1DiffN_1_Elec->GetYaxis()->SetTitle("");
11323   hTofKov1DiffN_1_Elec->GetYaxis()->CenterTitle();
11324   hTofKov1DiffN_1_Elec->SetFillColor(0);
11325   hTofKov1DiffN_1_Elec->SetBit(TH1::kCanRebin);
11326 
11327   TH1F *hTofKov1DiffN_Elec=new TH1F("hTofKov1DiffN_Elec",
11328                                    "hTofKov1DiffN_Elec",4000,-2,3);
11329   hTofKov1DiffN_Elec->GetXaxis()->SetTitle("Tof-Ckv time");
11330   hTofKov1DiffN_Elec->GetXaxis()->CenterTitle();
11331   hTofKov1DiffN_Elec->GetYaxis()->SetTitle("");
11332   hTofKov1DiffN_Elec->GetYaxis()->CenterTitle();
11333   hTofKov1DiffN_Elec->SetFillColor(0);
11334   hTofKov1DiffN_Elec->SetBit(TH1::kCanRebin);
11335 
11336   TH1F *hTofKov3Diff_Elec=new TH1F("hTofKov3Diff_Elec",
11337                                    "hTofKov3Diff_Elec",4000,-2,3);
11338   hTofKov3Diff_Elec->GetXaxis()->SetTitle("Tof - Ckv time");
11339   hTofKov3Diff_Elec->GetXaxis()->CenterTitle();
11340   hTofKov3Diff_Elec->GetYaxis()->SetTitle("");
11341   hTofKov3Diff_Elec->GetYaxis()->CenterTitle();
11342   hTofKov3Diff_Elec->SetFillColor(0);
11343   hTofKov3Diff_Elec->SetBit(TH1::kCanRebin);
11344 
11345   TH1F *hTofKov3DiffN_1_Elec=new TH1F("hTofKov3DiffN_1_Elec",
11346                                    "hTofKov3DiffN_1_Elec",4000,-2,3);
11347   hTofKov3DiffN_1_Elec->GetXaxis()->SetTitle("Tof - Ckv time");
11348   hTofKov3DiffN_1_Elec->GetXaxis()->CenterTitle();
11349   hTofKov3DiffN_1_Elec->GetYaxis()->SetTitle("");
11350   hTofKov3DiffN_1_Elec->GetYaxis()->CenterTitle();
11351   hTofKov3DiffN_1_Elec->SetFillColor(0);
11352   hTofKov3DiffN_1_Elec->SetBit(TH1::kCanRebin);
11353 
11354   TH1F *hTofKov3DiffN_Elec=new TH1F("hTofKov3DiffN_Elec",
11355                                    "hTofKov3DiffN_Elec",4000,-2,3);
11356   hTofKov3DiffN_Elec->GetXaxis()->SetTitle("Tof - Ckv time");
11357   hTofKov3DiffN_Elec->GetXaxis()->CenterTitle();
11358   hTofKov3DiffN_Elec->GetYaxis()->SetTitle("");
11359   hTofKov3DiffN_Elec->GetYaxis()->CenterTitle();
11360   hTofKov3DiffN_Elec->SetFillColor(0);
11361   hTofKov3DiffN_Elec->SetBit(TH1::kCanRebin);
11362 
11366   
11367   this->InitialiseLoopVariables();  
11368   
11369   for(Int_t event=0;event<fEvents;event++){
11370     
11371     this->SetLoopVariables(event);
11372 
11373     //do this cut before everything
11374     if (this->CutOnDeadChips()) continue;
11375     //don't cut on pid here anymore
11376 
11377     //fill histos before any cuts
11378     hOLChi2_Elec->Fill(fOLChi2);
11379     hKovADC1_Elec->Fill(fKovADC1);
11380     hKovADC2_Elec->Fill(fKovADC2);
11381     hKovADC3_Elec->Fill(fKovADC3);
11382     hTofDiff_Elec->Fill(fTofTDC2-fTofTDC0); 
11383     hTofKov1Diff_Elec->Fill(fTofADCTimeStamp1-fKovTimeStamp1);
11384     hTofKov3Diff_Elec->Fill(fTofADCTimeStamp1-fKovTimeStamp3);
11385  
11386     Double_t sumSigCor=0;
11387     Double_t sumMip=0;
11388 
11389     //get tclones arrays for this snarl
11390     TClonesArray &cTrk=*fTrkHitInfo;
11391     Int_t numTrkHits=fTrkHitInfo->GetEntries();
11392     TClonesArray &cUnTrk = *fUnTrkHitInfo;
11393     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
11394     TClonesArray &cXTalk = *fXTalkHits;
11395     Int_t numXTalkHits=fXTalkHits->GetEntries();
11396 
11398     //loop over the untracked hits in the snarl
11400     for (Int_t hit=0;hit<numUnTrkHits;hit++){
11401       //cast the tclonesarray up to a trackedhitinfo object
11402       CDTrackedHitInfo *hitInfo=
11403         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
11404 
11405       this->ReadInHitInfo(hitInfo);
11406 
11407       //cut out the bad channels
11408       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
11409 
11410       //check the channel's sanity
11411       this->StandardSanityChecks();
11412       
11413       //calc the scint hits time difference compared to tof
11414       this->CalcLowUpScint_TofDiff(fTime);
11415 
11416       //calculate the first and last planes
11417       this->CalcFirstLastPlane(fPlane);
11418       this->CalcNumPlanesHit(fPlane,fChargePe);
11419 
11420       //cut out the channels not to be used in calorimetry
11421       if (this->CutOnBadCalorimetry(fPlane,fStrip,fStripend)) continue;
11422 
11423       //do the calibration again with latest tables, temperatures,etc
11424       fChargeSigCor=this->ReCalibrate(fChargeAdc,
11425                                       fPlane,fStrip,fStripend);
11426 
11427       sumSigCor+=fChargeSigCor;
11428       sumMip+=fChargeMip;
11429       hSigCor_Elec->Fill(fChargeSigCor);
11430     }
11431 
11433     //loop over xtalk hits in the snarl
11435     for (Int_t hit=0;hit<numXTalkHits;hit++){
11436       CDXTalkHitInfo *hitInfo=
11437         dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
11438 
11439       this->ReadInHitInfo(hitInfo);
11440       
11441       //cut out the bad channels
11442       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
11443 
11444       //check the channel's sanity
11445       this->StandardSanityChecks();
11446 
11447       //calc the scint hits time difference compared to tof
11448       this->CalcLowUpScint_TofDiff(fTime);
11449 
11450       //calculate the first and last planes
11451       this->CalcFirstLastPlane(fPlane);
11452       this->CalcNumPlanesHit(fPlane,fChargePe);
11453 
11454       //cut out the channels not to be used in calorimetry
11455       if (this->CutOnBadCalorimetry(fPlane,fStrip,fStripend)) continue;
11456 
11457       //do the calibration again with latest tables, temperatures,etc
11458       fChargeSigCor=this->ReCalibrate(fChargeAdc,
11459                                       fPlane,fStrip,fStripend);
11460 
11461       sumSigCor+=fChargeSigCor;
11462       sumMip+=fChargeMip;
11463       hSigCor_Elec->Fill(fChargeSigCor);
11464     }
11465 
11467     //loop over the tracked hits
11469     for (Int_t hit=0;hit<numTrkHits;hit++){
11470       CDTrackedHitInfo *trackedHitInfo=
11471         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
11472           
11473       this->ReadInHitInfo(trackedHitInfo);
11474 
11475       //cut out the bad channels
11476       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
11477 
11478       //check the channel's sanity
11479       this->StandardSanityChecks();
11480 
11481       //calc the scint hits time difference compared to tof
11482       this->CalcLowUpScint_TofDiff(fTime);
11483 
11484       //calculate the first and last planes
11485       this->CalcFirstLastPlane(fPlane);
11486       this->CalcNumPlanesHit(fPlane,fChargePe);
11487 
11488       //cut out the channels not to be used in calorimetry
11489       if (this->CutOnBadCalorimetry(fPlane,fStrip,fStripend)) continue;
11490 
11491       //do the calibration again with latest tables, temperatures,etc
11492       fChargeSigCor=this->ReCalibrate(fChargeAdc,
11493                                       fPlane,fStrip,fStripend);
11494 
11495       sumSigCor+=fChargeSigCor;
11496       sumMip+=fChargeMip;
11497       hSigCor_Elec->Fill(fChargeSigCor);
11498     }
11500     //end of loop over the tracked hits
11502 
11503     //fill histos for all data
11504     hNumPlanesAll_Elec->Fill(fNumPlanesHitAll.size());
11505 
11506     if (!this->CutOnPidForElec() &&
11507         !this->CutOnEventLengthForElec() && 
11508         !this->CutOnScint_TofDiff()){
11509       hOLChi2_ElecN_1->Fill(fOLChi2);
11510     }
11511 
11512     if (!this->CutOnEventLengthForElec() && 
11513         !this->CutOnOverlapForElec() &&
11514         !this->CutOnScint_TofDiff()){
11515       hKovADC1_ElecN_1->Fill(fKovADC1);
11516       hKovADC2_ElecN_1->Fill(fKovADC2);
11517       hKovADC3_ElecN_1->Fill(fKovADC3);
11518       hTofDiff_ElecN_1->Fill(fTofTDC2-fTofTDC0); 
11519       hTofKov1DiffN_1_Elec->Fill(fTofADCTimeStamp1-fKovTimeStamp1);
11520       hTofKov3DiffN_1_Elec->Fill(fTofADCTimeStamp1-fKovTimeStamp3);
11521     }
11522 
11523     //::elec cuts 
11524     //cut on pid for electrons
11525     if (this->CutOnPidForElec()) continue;
11526     //make event length cuts
11527     if (this->CutOnEventLengthForElec()) continue;
11528     //make overlap cut
11529     if (this->CutOnOverlapForElec()) continue;
11530     //cut on the time difference between scint hits and tof hit
11531     if (this->CutOnScint_TofDiff()) continue;
11532     
11533     //fill pid histos
11534     hOLChi2_ElecN->Fill(fOLChi2);
11535     hKovADC1_ElecN->Fill(fKovADC1);
11536     hKovADC2_ElecN->Fill(fKovADC2);
11537     hKovADC3_ElecN->Fill(fKovADC3);
11538     hTofDiff_ElecN->Fill(fTofTDC2-fTofTDC0); 
11539     hTofKov1DiffN_Elec->Fill(fTofADCTimeStamp1-fKovTimeStamp1);
11540     hTofKov3DiffN_Elec->Fill(fTofADCTimeStamp1-fKovTimeStamp3);
11541 
11542     //fill histo after cuts
11543     hNumPlanesAllN_Elec->Fill(fNumPlanesHitAll.size());
11544     
11545     MAXMSG("CDAnalysis",Msg::kDebug,10)
11546       <<"Event passing plane cuts="<<event<<endl;
11547 
11548     //fill when one-sided (near-only) readout in a sensible way
11549     if (fRunNumber>=100000) hSumMip_Elec->Fill(sumMip);
11550     if (fRunNumber<100000) hSumMip_Elec->Fill(sumMip/2);
11551 
11552     hSumSigCor_Elec->Fill(sumSigCor);
11553     hSumMeu_Elec->Fill(sumSigCor/fSigCorPerMEU);
11554 
11555   }//end of for                                       
11556   
11560 
11561   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
11562 
11563   //turn off the stats box printing
11564   //gStyle->SetOptStat(0);
11565   gStyle->SetOptStat(1111111);
11566 
11567   TCanvas *cGeom_Elec=new TCanvas("cGeom_Elec","cGeom_Elec",
11568                                   0,0,1200,800);
11569   cGeom_Elec->SetFillColor(0);
11570   //cGeom_Elec->Divide(2,3);
11571   cGeom_Elec->cd(1);
11572   hNumPlanesAll_Elec->Draw();
11573   hNumPlanesAllN_Elec->SetLineColor(2);
11574   hNumPlanesAllN_Elec->Draw("sames");
11575 
11576   TCanvas *cEnDep_Elec=new TCanvas("cEnDep_Elec","cEnDep_Elec",
11577                                    0,0,1200,800);
11578   cEnDep_Elec->SetFillColor(0);
11579   cEnDep_Elec->Divide(2,3);
11580   cEnDep_Elec->cd(1);
11581   hSigCor_Elec->Draw();
11582   cEnDep_Elec->cd(2);
11583   hSumSigCor_Elec->Draw();
11584   cEnDep_Elec->cd(3);
11585   hSumMeu_Elec->Draw();
11586   cEnDep_Elec->cd(4);
11587   hSumMip_Elec->Draw();
11588 
11589   MSG("CDAnalysis",Msg::kInfo) 
11590     <<" ** Finished ElectronResponse method **"<<endl;
11591 }
11592 
11593 //......................................................................
11594 
11595 void CDAnalysis::MuonScatter()
11596 {
11597   MSG("CDAnalysis",Msg::kInfo) 
11598     <<" ** Running MuonScatter method... **"<<endl;
11599 
11600   //open the output file for the histograms
11601   fOutFile=this->OpenFile(fRunNumber,"MuonScat");
11602 
11603   //fS="Transverse hits in last plane";
11604   //TProfile* transLastPl=new TProfile(fS.c_str(),fS.c_str(),25,-1,24);
11605 
11606   vector<TProfile*> pTransAvEnDep;
11607   vector<TH1F*> hTransSumEnDep;
11608   vector<TH1F*> hTransHits;
11609 
11610   for (Int_t pl=0;pl<70;pl++){
11611     string sPl=Form("%d",pl);
11612     string sName="";
11613     
11614     sName="pTransAvEnDep";
11615     fS="Transverse Average Energy Deposition, plane=";
11616     fS+=sPl;
11617     sName+=sPl;
11618     pTransAvEnDep.push_back(new TProfile(sName.c_str(),fS.c_str(),
11619                                          27,-1,26));
11620     vector<TProfile*>::iterator prof=pTransAvEnDep.begin();
11621     (*prof)->GetXaxis()->SetTitle("Strip");
11622     (*prof)->GetYaxis()->SetTitle("Average Energy");
11623     (*prof)->GetXaxis()->CenterTitle();
11624     (*prof)->GetYaxis()->CenterTitle();
11625     
11626     sName="hTransSumEnDep";
11627     fS="Transverse Sum of Energy Deposition, plane=";
11628     fS+=sPl;
11629     sName+=sPl;
11630     hTransSumEnDep.push_back(new TH1F(sName.c_str(),fS.c_str(),
11631                                       27,-1,26));
11632     vector<TH1F*>::iterator hist=hTransSumEnDep.begin();
11633     (*hist)->GetXaxis()->SetTitle("Strip");
11634     (*hist)->GetYaxis()->SetTitle("Summed Energy");
11635     (*hist)->GetXaxis()->CenterTitle();
11636     (*hist)->GetYaxis()->CenterTitle();
11637 
11638     sName="hTransHits";
11639     fS="Transverse Hits, plane=";
11640     fS+=sPl;
11641     sName+=sPl;
11642     hTransHits.push_back(new TH1F(sName.c_str(),fS.c_str(),27,-1,26));
11643     hist=hTransHits.end();
11644     --hist;
11645     (*hist)->GetXaxis()->SetTitle("Strip");
11646     (*hist)->GetYaxis()->SetTitle("Num Hits");
11647     (*hist)->GetXaxis()->CenterTitle();
11648     (*hist)->GetYaxis()->CenterTitle();
11649   }
11650 
11651   TH1F *hLastPlane=new TH1F("hLastPlane","hLastPlane",66,-1,65);
11652   hLastPlane->GetXaxis()->SetTitle("Plane");
11653   hLastPlane->GetXaxis()->CenterTitle();
11654   hLastPlane->GetYaxis()->SetTitle("");
11655   hLastPlane->GetYaxis()->CenterTitle();
11656   hLastPlane->SetFillColor(0);
11657   hLastPlane->SetBit(TH1::kCanRebin);
11658 
11659   TH1F *hLastPlaneCut=new TH1F("hLastPlaneCut","hLastPlaneCut",
11660                                66,-1,65);
11661   hLastPlaneCut->GetXaxis()->SetTitle("Plane");
11662   hLastPlaneCut->GetXaxis()->CenterTitle();
11663   hLastPlaneCut->GetYaxis()->SetTitle("");
11664   hLastPlaneCut->GetYaxis()->CenterTitle();
11665   hLastPlaneCut->SetFillColor(0);
11666   hLastPlaneCut->SetLineColor(2);
11667   hLastPlaneCut->SetBit(TH1::kCanRebin);
11668 
11672   
11673   this->InitialiseLoopVariables();  
11674   
11675   for(Int_t event=0;event<fEvents;event++){
11676 
11677     this->SetLoopVariables(event);
11678 
11679     //calculate the last plane no xtalk
11680     Int_t lastPl=this->CalcLastPlaneOnTrkNoXTalk();
11681     hLastPlane->Fill(lastPl);
11682     if (lastPl<48 || lastPl>51) continue;
11683     hLastPlaneCut->Fill(lastPl);
11684 
11685     if (this->CutOnDeadChips()) continue;
11686     if (this->CutOnPid()) continue;
11687 
11688     //get tclones arrays for this snarl
11689     TClonesArray &cTrk=*fTrkHitInfo;
11690     Int_t numTrkHits=fTrkHitInfo->GetEntries();
11691     TClonesArray &cUnTrk = *fUnTrkHitInfo;
11692     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
11693     TClonesArray &cXTalk = *fXTalkHits;
11694     Int_t numXTalkHits=fXTalkHits->GetEntries();
11695           
11697     //loop over the untracked hits in the snarl
11699     for (Int_t hit=0;hit<numUnTrkHits;hit++){
11700       //cast the tclonesarray up to a trackedhitinfo object
11701       CDTrackedHitInfo *hitInfo=
11702         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
11703 
11704       this->ReadInHitInfo(hitInfo);
11705 
11706       //cut out the bad channels
11707       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
11708 
11709       //check the channel's sanity
11710       this->StandardSanityChecks();
11711 
11712     }
11713 
11715     //loop over xtalk hits in the snarl
11717     for (Int_t hit=0;hit<numXTalkHits;hit++){
11718       CDXTalkHitInfo *hitInfo=
11719         dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
11720 
11721       this->ReadInHitInfo(hitInfo);
11722       
11723       //cut out the bad channels
11724       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
11725 
11726       //check the channel's sanity
11727       this->StandardSanityChecks();
11728 
11729     }
11730 
11732     //loop over the tracked hits
11734     for (Int_t hit=0;hit<numTrkHits;hit++){
11735       CDTrackedHitInfo *trackedHitInfo=
11736         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
11737           
11738       this->ReadInHitInfo(trackedHitInfo);
11739 
11740       //cut out the bad channels
11741       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
11742 
11743       //check the channel's sanity
11744       this->StandardSanityChecks();
11745 
11746       //calculate the first and last planes
11747       this->CalcFirstLastPlane(fPlane);
11748 
11749       pTransAvEnDep[fPlane]->Fill(fStrip,fChargeMip);
11750       hTransSumEnDep[fPlane]->Fill(fStrip,fChargeMip);
11751       hTransHits[fPlane]->Fill(fStrip,1);
11752     }
11754     //end of loop over the tracked hits
11756   }
11757 
11761 
11762   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
11763 
11764   //turn off the stats box printing
11765   gStyle->SetOptStat(0);
11766 
11767   //turn on the stats box printing
11768   gStyle->SetOptStat(1111111);
11769 
11770   TCanvas *cTransHits=new TCanvas("cTransHits","cTransHits",
11771                                   0,0,1200,800);
11772   cTransHits->SetFillColor(0);
11773   cTransHits->Divide(4,4);
11774   Int_t i=0;
11775   vector<TH1F*>::iterator hist=hTransHits.begin();
11776   cTransHits->cd(++i);//1
11777   (*(hist+1))->Draw();
11778   cTransHits->cd(++i);
11779   (*(hist+4))->Draw();
11780   cTransHits->cd(++i);
11781   (*(hist+8))->Draw();
11782   cTransHits->cd(++i);//4
11783   (*(hist+12))->Draw();
11784   cTransHits->cd(++i);
11785   (*(hist+16))->Draw();
11786   cTransHits->cd(++i);//6
11787   (*(hist+20))->Draw();
11788   cTransHits->cd(++i);
11789   (*(hist+24))->Draw();
11790   cTransHits->cd(++i);//8
11791   (*(hist+28))->Draw();
11792   cTransHits->cd(++i);
11793   (*(hist+32))->Draw();
11794   cTransHits->cd(++i);//10
11795   (*(hist+36))->Draw();
11796   cTransHits->cd(++i);
11797   (*(hist+40))->Draw();
11798   cTransHits->cd(++i);//12
11799   (*(hist+44))->Draw();
11800   cTransHits->cd(++i);
11801   (*(hist+48))->Draw();
11802   cTransHits->cd(++i);//14
11803   (*(hist+52))->Draw();
11804   cTransHits->cd(++i);
11805   (*(hist+56))->Draw();
11806   cTransHits->cd(++i);//16
11807   (*(hist+59))->Draw();
11808 
11809   TCanvas *cPlCut=new TCanvas("cPlCut","cPlCut",0,0,1200,800);
11810   cPlCut->SetFillColor(0);
11811   hLastPlane->Draw();
11812   hLastPlaneCut->Draw("sames");
11813 
11814   Bool_t printPs=false;
11815   if (printPs){
11816     TCanvas *cProf=new TCanvas("cProf","cProf",0,0,1200,800);
11817     cProf->SetFillColor(0);
11818     string sName="TransverseEnergyDep.ps";
11819     cProf->Print((sName+"[").c_str());
11820     gErrorIgnoreLevel=1;
11821     //plot the prof 
11822     for (vector<TProfile*>::iterator prof=pTransAvEnDep.begin();
11823          prof!=pTransAvEnDep.end();++prof){      
11824       cProf->Clear();
11825       (*prof)->Draw();
11826       //(*prof)->SetTitle("Transverse Hits in Plane");
11827       (*prof)->GetXaxis()->SetTitle("Strip");
11828       (*prof)->GetYaxis()->SetTitle("Average MIPs");
11829       (*prof)->GetXaxis()->CenterTitle();
11830       (*prof)->GetYaxis()->CenterTitle();
11831       cProf->Print(sName.c_str());
11832     }
11833     cProf->Print((sName+"]").c_str());
11834     
11835     //plot second
11836     TCanvas *cProf2=new TCanvas("cProf2","cProf2",0,0,1200,800);
11837     cProf2->SetFillColor(0);
11838     sName="TransverseSumEnergyDep.ps";
11839     gErrorIgnoreLevel=0;
11840     cProf2->Print((sName+"[").c_str());
11841     gErrorIgnoreLevel=1;
11842     //plot
11843     for (vector<TH1F*>::iterator hist=hTransSumEnDep.begin();
11844          hist!=hTransSumEnDep.end();++hist){      
11845       cProf2->Clear();
11846       (*hist)->Draw();
11847       //(*hist)->SetTitle("Transverse Hits in Plane");
11848       (*hist)->GetXaxis()->SetTitle("Strip");
11849       (*hist)->GetYaxis()->SetTitle("Summed Energy");
11850       (*hist)->GetXaxis()->CenterTitle();
11851       (*hist)->GetYaxis()->CenterTitle();
11852       cProf2->Print(sName.c_str());
11853     }
11854     cProf2->Print((sName+"]").c_str());
11855     
11856     //plot
11857     sName="TransverseHits.ps";
11858     gErrorIgnoreLevel=0;
11859     cProf2->Print((sName+"[").c_str());
11860     gErrorIgnoreLevel=1;
11861     //plot
11862     for (vector<TH1F*>::iterator hist=hTransHits.begin();
11863          hist!=hTransHits.end();++hist){      
11864       cProf2->Clear();
11865       (*hist)->Draw();
11866     }
11867     cProf2->Print((sName+"]").c_str());
11868   }
11869 
11870   MSG("CDAnalysis",Msg::kInfo) 
11871     <<" ** Finished MuonScatter method **"<<endl;
11872 }
11873 
11874 //......................................................................
11875 
11876 void CDAnalysis::MuonStVsPl()
11877 {
11878   MSG("CDAnalysis",Msg::kInfo) 
11879     <<" ** Running MuonStVsPl method... **"<<endl;
11880   
11881   vector<TH1F*> hAdc(4); 
11882 
11883   for (UInt_t i=0;i<hAdc.size();i++){
11884     string sNum=Form("%d",i);
11885     fS="Adc distribution"+sNum;
11886     hAdc[i]=new TH1F(fS.c_str(),fS.c_str(),4000,-20,20000);
11887     hAdc[i]->GetXaxis()->SetTitle("Adc");
11888     hAdc[i]->GetXaxis()->CenterTitle();
11889     hAdc[i]->GetYaxis()->SetTitle("");
11890     hAdc[i]->GetYaxis()->CenterTitle();
11891     hAdc[i]->SetFillColor(0);
11892     hAdc[i]->SetBit(TH1::kCanRebin);
11893   }
11894 
11895   TH1F *hStrip=new TH1F("hStrip","Strips hit",100,-2,30);
11896   hStrip->GetXaxis()->SetTitle("Strip");
11897   hStrip->GetXaxis()->CenterTitle();
11898   hStrip->GetYaxis()->SetTitle("");
11899   hStrip->GetYaxis()->CenterTitle();
11900   hStrip->SetFillColor(0);
11901   hStrip->SetBit(TH1::kCanRebin);
11902 
11903   TH1F *hPlane=new TH1F("hPlane","Planes hit",200,-2,75);
11904   hPlane->GetXaxis()->SetTitle("Plane");
11905   hPlane->GetXaxis()->CenterTitle();
11906   hPlane->GetYaxis()->SetTitle("");
11907   hPlane->GetYaxis()->CenterTitle();
11908   hPlane->SetFillColor(0);
11909   hPlane->SetBit(TH1::kCanRebin);
11910 
11911   fS="Strip Vs Plane EnergyDep Map";
11912   TProfile2D* pStVsPlEnDep=new TProfile2D(fS.c_str(),fS.c_str(),
11913                                            64,-2,62,30,-3,27);
11914   pStVsPlEnDep->GetXaxis()->SetTitle("Plane");
11915   pStVsPlEnDep->GetXaxis()->CenterTitle();
11916   pStVsPlEnDep->GetYaxis()->SetTitle("Strip");
11917   pStVsPlEnDep->GetYaxis()->CenterTitle();
11918   pStVsPlEnDep->SetFillColor(0);
11919   //pStVsPlEnDep->SetMaximum(15000);
11920 
11921   fS="Strip Vs Plane SigCor Map";
11922   TProfile2D* pStVsPlSigCor=new TProfile2D(fS.c_str(),fS.c_str(),
11923                                            64,-2,62,30,-3,27);
11924   pStVsPlSigCor->GetXaxis()->SetTitle("Plane");
11925   pStVsPlSigCor->GetXaxis()->CenterTitle();
11926   pStVsPlSigCor->GetYaxis()->SetTitle("Strip");
11927   pStVsPlSigCor->GetYaxis()->CenterTitle();
11928   pStVsPlSigCor->SetFillColor(0);
11929   //pStVsPlSigCor->SetMaximum(15000);
11930 
11931   fS="Strip Vs Plane Adc Map";
11932   TProfile2D* pStVsPlAdc=new TProfile2D(fS.c_str(),fS.c_str(),
11933                                            64,-2,62,30,-3,27);
11934   pStVsPlAdc->GetXaxis()->SetTitle("Plane");
11935   pStVsPlAdc->GetXaxis()->CenterTitle();
11936   pStVsPlAdc->GetYaxis()->SetTitle("Strip");
11937   pStVsPlAdc->GetYaxis()->CenterTitle();
11938   pStVsPlAdc->SetFillColor(0);
11939   //pStVsPlAdc->SetMaximum(15000);
11940 
11941   fS="Strip Vs Plane Num Hits Map";
11942   TH2F* hStVsPlNum=new TH2F(fS.c_str(),fS.c_str(),64,-2,62,30,-3,27);
11943   hStVsPlNum->GetXaxis()->SetTitle("Plane");
11944   hStVsPlNum->GetXaxis()->CenterTitle();
11945   hStVsPlNum->GetYaxis()->SetTitle("Strip");
11946   hStVsPlNum->GetYaxis()->CenterTitle();
11947   hStVsPlNum->SetFillColor(0);
11948   //hStVsPlNum->SetMaximum(15000);
11949 
11953   
11954   this->InitialiseLoopVariables();  
11955   
11956   for(Int_t event=0;event<fEvents;event++){
11957     
11958     this->SetLoopVariables(event);
11959 
11960     //get tclones arrays for this snarl
11961     TClonesArray &cTrk=*fTrkHitInfo;
11962     Int_t numTrkHits=fTrkHitInfo->GetEntries();
11963 
11964     //loop over the tracked hits
11965     //to calc first and last planes
11966     for (Int_t hit=0;hit<numTrkHits;hit++){
11967       CDTrackedHitInfo *trackedHitInfo=
11968         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
11969           
11970       this->ReadInHitInfo(trackedHitInfo);
11971 
11972       //calculate the first and last planes
11973       this->CalcFirstLastPlane(fPlane);
11974       this->CalcNumPlanesHitTrk(fPlane);
11975     }
11976     //end of loop over the tracked hits
11977 
11978     //check track length and composition
11979     if (fLastPlane<40 || fNumPlanesHitTrk.size()<35) continue;
11980 
11982     //loop over the tracked hits again...
11984     for (Int_t hit=0;hit<numTrkHits;hit++){
11985       CDTrackedHitInfo *trackedHitInfo=
11986         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
11987           
11988       this->ReadInHitInfo(trackedHitInfo);
11989 
11990       //cut out the bad channels
11991       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
11992 
11993       //check the channel's sanity
11994       this->StandardSanityChecks();
11995 
11996       //calculate the first and last planes
11997       this->CalcFirstLastPlane(fPlane);
11998 
11999       if (fPlane==2 && fStrip==19) {
12000         hAdc[0]->Fill(fChargeAdc);
12001         MSG("CDAnalysis",Msg::kInfo)
12002           <<"e="<<event<<", adc="<<fChargeAdc<<endl;
12003         
12004       }
12005       else if (fPlane==5 && fStrip==19) hAdc[1]->Fill(fChargeAdc);
12006       else if (fPlane==13 && fStrip==11) hAdc[2]->Fill(fChargeAdc);
12007       else if (fPlane==5 && fStrip==19) hAdc[3]->Fill(fChargeAdc);
12008 
12009       if (fChargeAdc>2500 && fPlane>0){
12010         MSG("CDAnalysis",Msg::kInfo)
12011           <<"e="<<event<<", adc="<<fChargeAdc<<endl;
12012       
12013 
12014       //fill histos
12015       hPlane->Fill(fPlane);
12016       hStrip->Fill(fStrip);
12017       pStVsPlSigCor->Fill(fPlane,fStrip,fChargeMip);
12018       pStVsPlAdc->Fill(fPlane,fStrip,fChargeAdc);
12019       hStVsPlNum->Fill(fPlane,fStrip,1);
12020       }
12021     }
12023     //end of loop over the tracked hits
12025 
12026   }//end of for                                       
12027   
12031 
12032   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
12033 
12034   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
12035   cGeom->SetFillColor(0);
12036   cGeom->Divide(2,2);
12037   cGeom->cd(1);
12038   hPlane->Draw();
12039   cGeom->cd(2);
12040   hStrip->Draw();
12041   cGeom->cd(3);
12042 
12043   cGeom->cd(4);
12044 
12045   TCanvas *cAdc=new TCanvas("cAdc","Adc",0,0,1200,800);
12046   cAdc->SetFillColor(0);
12047   cAdc->Divide(2,2);
12048   cAdc->cd(1);
12049   hAdc[0]->Draw();
12050   cAdc->cd(2);
12051   hAdc[1]->Draw();
12052   cAdc->cd(3);
12053   hAdc[2]->Draw();
12054   cAdc->cd(4);
12055   hAdc[3]->Draw();
12056 
12057   TCanvas *cStVsPlSigCor=new TCanvas("cStVsPlSigCor","StVsPlSigCor",
12058                                     0,0,1200,800);
12059   cStVsPlSigCor->SetFillColor(0);
12060   pStVsPlSigCor->Draw("colz");
12061 
12062   TCanvas *cStVsPlAdc=new TCanvas("cStVsPlAdc","StVsPlAdc",
12063                                     0,0,1200,800);
12064   cStVsPlAdc->SetFillColor(0);
12065   pStVsPlAdc->Draw("colz");
12066 
12067   TCanvas *cStVsPlNum=new TCanvas("cStVsPlNum","StVsPlNum",
12068                                   0,0,1200,800);
12069   cStVsPlNum->SetFillColor(0);
12070   hStVsPlNum->Draw("colz");
12071 
12072   MSG("CDAnalysis",Msg::kInfo) 
12073     <<" ** Finished MuonStVsPl method **"<<endl;
12074 }
12075 
12076 //......................................................................
12077 
12078 void CDAnalysis::Template2()
12079 {
12080   MSG("CDAnalysis",Msg::kInfo) 
12081     <<" ** Running Template2 method... **"<<endl;
12082 
12083   map<Int_t,Int_t> numPlanesHit;
12084 
12088   
12089   this->InitialiseLoopVariables();  
12090   
12091   for(Int_t event=0;event<fEvents;event++){
12092     
12093     this->SetLoopVariables(event);
12094 
12095     if (this->CutOnDeadChips()) continue;
12096     if (this->CutOnPid()) continue;
12097 
12098     //get tclones arrays for this snarl
12099     TClonesArray &cTrk=*fTrkHitInfo;
12100     Int_t numTrkHits=fTrkHitInfo->GetEntries();
12101     TClonesArray &cUnTrk = *fUnTrkHitInfo;
12102     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
12103     //CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
12104     TClonesArray &cXTalk = *fXTalkHits;
12105     Int_t numXTalkHits=fXTalkHits->GetEntries();
12106           
12108     //loop over the untracked hits in the snarl
12110     for (Int_t hit=0;hit<numUnTrkHits;hit++){
12111       //cast the tclonesarray up to a trackedhitinfo object
12112       CDTrackedHitInfo *hitInfo=
12113         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
12114 
12115       this->ReadInHitInfo(hitInfo);
12116 
12117       //cut out the bad channels
12118       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
12119 
12120       //check the channel's sanity
12121       this->StandardSanityChecks();
12122 
12123     }
12124 
12126     //loop over xtalk hits in the snarl
12128     for (Int_t hit=0;hit<numXTalkHits;hit++){
12129       CDXTalkHitInfo *hitInfo=
12130         dynamic_cast<CDXTalkHitInfo*>(cXTalk[hit]);
12131 
12132       this->ReadInHitInfo(hitInfo);
12133       
12134       //cut out the bad channels
12135       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
12136 
12137       //check the channel's sanity
12138       this->StandardSanityChecks();
12139 
12140     }
12141 
12143     //loop over the tracked hits
12145     for (Int_t hit=0;hit<numTrkHits;hit++){
12146       CDTrackedHitInfo *trackedHitInfo=
12147         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
12148           
12149       this->ReadInHitInfo(trackedHitInfo);
12150 
12151       //cut out the bad channels
12152       if (this->CutOnBadPedestals(fPlane,fStrip,fStripend)) continue;
12153 
12154       //check the channel's sanity
12155       this->StandardSanityChecks();
12156 
12157       if (fPlane<fFirstPlane) fFirstPlane=fPlane;
12158       if (fPlane>fLastPlane) fLastPlane=fPlane;
12159       if (fPlane>fLastPlaneOdd && fPlane%2!=0) fLastPlaneOdd=fPlane;
12160       if (fPlane>fLastPlaneEven && fPlane%2==0) fLastPlaneEven=fPlane;
12161 
12162       //count the number of planes hit
12163       numPlanesHit[fPlane]++;
12164 
12165     }
12167     //end of loop over the tracked hits
12169 
12170     //check that a first plane was actually found
12171     if (fFirstPlane<0 || fFirstPlane>59) continue;
12172 
12173     //make cuts
12174     if (numPlanesHit.size()<40) continue;
12175     if (fFirstPlane<0 || fFirstPlane>59) continue;
12176     if (fLastPlane>57) continue;//cut out through going muons, no 58,59
12177 
12178   }
12179 
12183 
12184   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
12185 
12186   MSG("CDAnalysis",Msg::kInfo) 
12187     <<" ** Finished Template2 method **"<<endl;
12188 }
12189 
12190 //......................................................................
12191  
12192 string CDAnalysis::Pct(Double_t top,Double_t bottom) const
12193 {
12195   Double_t percent=-1;
12196   string sPercent="notset";
12197   if (bottom!=0){
12198     percent=top/bottom;
12199     percent*=100;
12200     sPercent=Form("%.1f",percent);
12201   }
12202   else{
12203     sPercent="fpe!";
12204   }
12205   return sPercent;
12206 }
12207 
12208 //......................................................................
12209 
12210 Double_t CDAnalysis::dE_dxIterative(MuEnergyLoss& mat,
12211                                     Double_t energyRemaining,
12212                                     Double_t totalThk,Double_t rho,
12213                                     Double_t energyCutOff,
12214                                     Int_t slices) const
12215 {
12218 
12219   Double_t totalEnergyDeposited=0;
12220   Double_t sliceThk=totalThk/slices;
12221 
12222   for (Int_t s=0;s<slices;s++){
12223 
12224     if (energyRemaining<energyCutOff){
12225       MSG("CDAnalysis",Msg::kInfo) 
12226         <<"All energy lost at slice "<<s+1<<"/"<<slices
12227         <<" ("<<100.*s*sliceThk/totalThk<<"% through material)"<<endl;
12228       return -1;
12229     }
12230 
12231     //calculate energy deposited in the slice
12232     //Double_t energyDeposited=mat.dE_dx(energyRemaining)*rho*sliceThk;
12233     double e=energyRemaining;
12234     Double_t energyDeposited=mat.dE_dx
12235       (e,Process::eIonization)*rho*sliceThk;
12236     totalEnergyDeposited+=energyDeposited;
12237 
12238     //increment the energy remaining
12239     energyRemaining-=energyDeposited;
12240   }
12241 
12242   return totalEnergyDeposited;
12243 }
12244 
12245 //......................................................................
12246  
12247 void CDAnalysis::Bb() const
12248 {
12249   Float_t sum15_18=0;
12250   Float_t sum15_18Sc=0;
12251   Float_t av15PlanesSc=0;
12252   Float_t avPlanes0to14Sc=0;
12253   Float_t sum15_18Counter=0;
12254   vector<Double_t> eDepositedPl;
12255  
12256   //create simpleMC object
12257   CDSimpleMC mc;
12258   mc.SetThkFe(2.54);
12259   mc.SetParticleMomentum(5000);
12260   //run mc
12261   mc.RunMC();
12262   //get ratios too
12263   mc.CalcRatioScToFe();
12264   /*
12265 //2.5
12266 Using pl=0 in my extra special window, endep=2.00385
12267 Using pl=1 in my extra special window, endep=1.99883
12268 Using pl=2 in my extra special window, endep=1.99371
12269 Using pl=3 in my extra special window, endep=1.98848
12270 Using pl=4 in my extra special window, endep=1.98315
12271 Using pl=5 in my extra special window, endep=1.97771
12272 Using pl=6 in my extra special window, endep=1.97217
12273 Using pl=7 in my extra special window, endep=1.96654
12274 Using pl=8 in my extra special window, endep=1.96082
12275 Using pl=9 in my extra special window, endep=1.95502
12276 Using pl=10 in my extra special window, endep=1.94916
12277 Using pl=11 in my extra special window, endep=1.94325
12278 Using pl=12 in my extra special window, endep=1.93733
12279 Using pl=13 in my extra special window, endep=1.93142
12280 Using pl=14 in my extra special window, endep=1.92558
12281 
12282   //2.54
12283  Using pl=0 in my extra special window, endep=2.00385
12284 Using pl=1 in my extra special window, endep=1.99876
12285 Using pl=2 in my extra special window, endep=1.99355
12286 Using pl=3 in my extra special window, endep=1.98824
12287 Using pl=4 in my extra special window, endep=1.98283
12288 Using pl=5 in my extra special window, endep=1.9773
12289 Using pl=6 in my extra special window, endep=1.97168
12290 Using pl=7 in my extra special window, endep=1.96595
12291 Using pl=8 in my extra special window, endep=1.96014
12292 Using pl=9 in my extra special window, endep=1.95425
12293 Using pl=10 in my extra special window, endep=1.94829
12294 Using pl=11 in my extra special window, endep=1.94229
12295 Using pl=12 in my extra special window, endep=1.93628
12296 Using pl=13 in my extra special window, endep=1.93029
12297 Using pl=14 in my extra special window, endep=1.92439
12298 
12299 //2.5
12300 Using pl=17 in my special window, endep=2.0194
12301 Using pl=18 in my special window, endep=2.01471
12302 Using pl=19 in my special window, endep=2.00992
12303 Using pl=20 in my special window, endep=2.00503
12304 Using pl=21 in my special window, endep=2.00004
12305 Using pl=22 in my special window, endep=1.99494
12306 Using pl=23 in my special window, endep=1.98973
12307 Using pl=24 in my special window, endep=1.98442
12308 Using pl=25 in my special window, endep=1.97901
12309 Using pl=26 in my special window, endep=1.9735
12310 Using pl=27 in my special window, endep=1.96789
12311 Using pl=28 in my special window, endep=1.96219
12312 Using pl=29 in my special window, endep=1.95641
12313 Using pl=30 in my special window, endep=1.95056
12314 Using pl=31 in my special window, endep=1.94466
12315 
12316 //2.54
12317 Using pl=17 in my special window, endep=2.01823
12318 Using pl=18 in my special window, endep=2.01345
12319 Using pl=19 in my special window, endep=2.00856
12320 Using pl=20 in my special window, endep=2.00357
12321 Using pl=21 in my special window, endep=1.99847
12322 Using pl=22 in my special window, endep=1.99326
12323 Using pl=23 in my special window, endep=1.98794
12324 Using pl=24 in my special window, endep=1.98252
12325 Using pl=25 in my special window, endep=1.97699
12326 Using pl=26 in my special window, endep=1.97136
12327 Using pl=27 in my special window, endep=1.96563
12328 Using pl=28 in my special window, endep=1.95981
12329 Using pl=29 in my special window, endep=1.95391
12330 Using pl=30 in my special window, endep=1.94795
12331 Using pl=31 in my special window, endep=1.94195
12332   */
12333 
12334 
12335 
12336   for (UInt_t i=0;i<mc.fEnScDeposited.size();i++){
12337     if (i<=14){
12338       MSG("CDAnalysis",Msg::kInfo)
12339         <<"Using pl="<<i<<" in my extra special window, endep="
12340         <<mc.fEnScDeposited[i]<<endl; 
12341       avPlanes0to14Sc+=mc.fEnScDeposited[i];
12342     }
12343 
12344     if (i>=17 && i<=31){
12345       MSG("CDAnalysis",Msg::kInfo)
12346         <<"Using pl="<<i<<" in my special window, endep="
12347         <<mc.fEnScDeposited[i]<<endl; 
12348       av15PlanesSc+=mc.fEnScDeposited[i];
12349     }
12350   }
12351   //calc the average
12352   av15PlanesSc/=15;
12353   avPlanes0to14Sc/=15;
12354   MSG("CDAnalysis",Msg::kInfo)
12355     <<"Average scint en. dep. for planes 17-31 inclusive="
12356     <<av15PlanesSc<<endl
12357     <<"Average scint en. dep. for planes 0-14 inclusive="
12358     <<avPlanes0to14Sc<<endl;
12359   
12361   //section for sliding window
12363   
12364   vector<TProfile*> pSigCorVsDist;
12365   vector<Int_t> vWindowSize;
12366   vector<Float_t> bigAv;
12367   vector<Int_t> bigAvCounter;
12368   Int_t minEventLength=40;
12369 
12370   //need a new vector for this!!!!
12373   MSG("CDAnalysis",Msg::kInfo) 
12374     <<"size="<<mc.fEnScDeposited.size()<<endl;
12375 
12376   //initialise the profile histos
12377   for (Int_t p=20;p>1;p--){
12378     vWindowSize.push_back(p);
12379     bigAv.push_back(0);
12380     bigAvCounter.push_back(0);
12381   }
12382   
12383   for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
12384        windowSize!=vWindowSize.end();++windowSize){
12385     
12386     string sName=Form("%d",*windowSize);
12387     pSigCorVsDist.push_back
12388       (new TProfile(("pSigCorVsDist"+sName).c_str(),
12389                     ("pSigCorVsDist"+sName).c_str(),100,-2,40));
12390   }
12391 
12392   vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
12393   vector<Float_t>::iterator av=bigAv.begin();
12394   vector<Int_t>::iterator count=bigAvCounter.begin();
12395   
12396   //loop over the different window sizes
12397   for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
12398        windowSize!=vWindowSize.end();++windowSize){
12399     MSG("CDAnalysis",Msg::kDebug)
12400       <<"Window size="<<*windowSize<<endl;
12401  
12402     //slide the window along from the end to 40-windowSize
12403     for (Int_t p=0;p<minEventLength-*windowSize;p++){
12404       Int_t lastPlane=mc.fEnScDeposited.size()-1;
12405       Int_t windowStart=lastPlane-p;
12406 
12407       //loop through the hits in the window      
12408       for (Int_t i=0;i<*windowSize;i++){
12409         Int_t plane=windowStart-i;
12410         
12411         (*prof)->Fill(p,mc.fEnScDeposited[plane]);
12412         (*av)+=mc.fEnScDeposited[plane];
12413         (*count)++;
12414 
12415         //calculate the best window value
12416         if (*windowSize==15 && windowStart==lastPlane-18){
12417           MSG("CDAnalysis",Msg::kInfo)
12418             <<"Using pl="<<plane<<" in window"<<endl;
12419           sum15_18+=mc.fEnDepositedPl[plane];
12420           sum15_18Sc+=mc.fEnScDeposited[plane];
12421           sum15_18Counter++;
12422         }
12423       }
12424 
12425       
12426 
12427     }
12428     av++;
12429     count++;
12430     prof++;
12431   }
12432 
12433   //turn on the stats box printing
12434   gStyle->SetOptStat(11);
12435 
12436   TCanvas *cProf=new TCanvas("cProf","Prof",0,0,1200,800);
12437   cProf->SetFillColor(0);
12438   string sName="SlidingWindowBB.ps";
12439   cProf->Print((sName+"[").c_str());
12440   gErrorIgnoreLevel=1;
12441   //plot the unnormalised prof first
12442   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
12443        prof!=pSigCorVsDist.end();++prof){      
12444     cProf->Clear();
12445     (*prof)->Draw();
12446     (*prof)->SetTitle("Energy Deposited in Sliding Window");
12447     (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
12448     (*prof)->GetYaxis()->SetTitle("Energy Deposited (MeV)");
12449     (*prof)->GetXaxis()->CenterTitle();
12450     (*prof)->GetYaxis()->CenterTitle();
12451     cProf->Print(sName.c_str());
12452   }
12453 
12454   //now normalise the prof
12455   av=bigAv.begin();
12456   count=bigAvCounter.begin();
12457   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
12458        prof!=pSigCorVsDist.end();++prof){
12459       
12460     //normalise the prof and scale the axes
12461     MSG("CDAnalysis",Msg::kInfo)
12462       <<"bigCounter="<<*count<<", bigAv="<<*av<<endl;
12463     if (*av>0) (*prof)->Scale((*count)/(*av));
12464     (*prof)->SetMaximum(1.2);
12465     (*prof)->SetMinimum(0.8);
12466       
12467     cProf->Clear();
12468     (*prof)->Draw();
12469     (*prof)->SetTitle("Normalised Energy Deposited in Sliding Window");
12470     (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
12471     (*prof)->GetYaxis()->SetTitle("Normalised Energy Deposited");
12472     (*prof)->GetXaxis()->CenterTitle();
12473     (*prof)->GetYaxis()->CenterTitle();
12474     cProf->Print(sName.c_str());
12475     av++;
12476     count++;
12477   }
12478   //close the file
12479   gErrorIgnoreLevel=0;
12480   cProf->Print((sName+"]").c_str());
12481 
12482   TLegend *legend = new TLegend(0.85, 0.7, 0.9, 0.9);
12483   legend->SetBorderSize(0);
12484   legend->SetFillColor(0);
12485   legend->SetTextSize(0.035);
12486 
12487   //now do a few profs on the same plot
12488   TCanvas *cProf2=new TCanvas("cProf2","Prof",0,0,1200,800);
12489   cProf2->SetFillColor(0);
12490   sName="SlidingWindowAll.ps";
12491   //cProf2->Print((sName+"[").c_str());
12492   Int_t counter=0;
12493   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
12494        prof!=pSigCorVsDist.end();++prof){
12495 
12496     (*prof)->SetMaximum(1.09);
12497     (*prof)->SetMinimum(0.96);
12498 
12499     //count which prof got to
12500     counter++;
12501 
12502     //decide which profs to draw
12503     static Bool_t firstTime=true;
12504     if (counter==1 || counter==6 || counter==11){ 
12505       if (firstTime) {
12506         (*prof)->Draw();
12507         firstTime=false;
12508       }
12509       else  (*prof)->Draw("sames");
12510 
12511       (*prof)->SetTitle("Normalised Energy Deposited in Sliding Window");
12512       (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
12513       (*prof)->GetYaxis()->SetTitle("Normalised Energy Deposition");
12514       (*prof)->GetXaxis()->CenterTitle();
12515       (*prof)->GetYaxis()->CenterTitle();
12516       static Int_t color=2;
12517       (*prof)->SetLineColor(color);
12518       color+=2;
12519       string sWindowSize=Form("%d",21-counter);
12520       string sGraph=" Window size = ";
12521       sGraph+=sWindowSize;
12522       sGraph+=" planes";
12523       legend->AddEntry((*prof),sGraph.c_str(),"l");
12524     }
12525   }
12526   legend->Draw();
12527 
12528   this->FlipVector(mc.fXScPlanes);
12529   TGraph* eLossSc=TGraphVect(mc.fXScPlanes,mc.fEnScDeposited);
12530   TCanvas *cELossSc=new TCanvas("cELossSc","ELossSc",
12531                                    0,0,1200,800);
12532   cELossSc->SetFillColor(0);
12533   eLossSc->Draw("AP");
12534   eLossSc->SetTitle("Energy Loss in Scintillator");
12535   eLossSc->GetXaxis()->SetTitle("Distance from end of track (planes)");
12536   eLossSc->GetYaxis()->SetTitle("Energy Loss (MeV)");
12537   eLossSc->GetXaxis()->CenterTitle();
12538   eLossSc->GetYaxis()->CenterTitle();
12539   eLossSc->SetMarkerStyle(3);
12540   eLossSc->SetMarkerColor(2);
12541   eLossSc->SetMarkerSize(0.8);
12542 
12543   this->FlipVector(mc.fX);
12544   TGraph* energyLoss=TGraphVect(mc.fX,mc.fEnDeposited);
12545   TCanvas *cEnergyLoss=new TCanvas("cEnergyLoss","EnergyLoss",
12546                                    0,0,1200,800);
12547   cEnergyLoss->SetFillColor(0);
12548   energyLoss->Draw("AP");
12549   energyLoss->SetTitle("Energy Loss in Scintillator and Iron");
12550   energyLoss->GetXaxis()->SetTitle("Distance from end of track (cm)");
12551   energyLoss->GetYaxis()->SetTitle("Energy Loss (MeV)");
12552   energyLoss->GetXaxis()->CenterTitle();
12553   energyLoss->GetYaxis()->CenterTitle();
12554   energyLoss->SetMarkerStyle(3);
12555   energyLoss->SetMarkerColor(2);
12556   energyLoss->SetMarkerSize(0.8);
12557 
12558   this->FlipVector(mc.fXPlanes);
12559   TGraph* energyloss2=TGraphVect(mc.fXPlanes,mc.fEnDeposited);
12560   TCanvas *cEnergyloss2=new TCanvas("cEnergyloss2","Energyloss2",
12561                                    0,0,1200,800);
12562   cEnergyloss2->SetFillColor(0);
12563   energyloss2->Draw("AP");
12564   energyloss2->SetTitle("Energy Loss in Scintillator and Iron");
12565   energyloss2->GetXaxis()->SetTitle("Distance from end of track (planes)");
12566   energyloss2->GetYaxis()->SetTitle("Energy Loss (MeV)");
12567   energyloss2->GetXaxis()->CenterTitle();
12568   energyloss2->GetYaxis()->CenterTitle();
12569   energyloss2->SetMarkerStyle(3);
12570   energyloss2->SetMarkerColor(2);
12571   energyloss2->SetMarkerSize(0.8);
12572 
12573   this->FlipVector(mc.fXFe);
12574   TGraph* gXFevsEn=TGraphVect(mc.fXFe,mc.fEnFeDeposited);
12575   this->FlipVector(mc.fXSc);
12576   TGraph* gXScvsEn=TGraphVect(mc.fXSc,mc.fEnScDeposited);
12577   this->FlipVector(mc.fXAlx2);
12578   TGraph* gXAlx2vsEn=TGraphVect(mc.fXAlx2,mc.fEnAlx2Deposited);
12579   this->FlipVector(mc.fXTiO2x2);
12580   TGraph* gXTiO2x2vsEn=TGraphVect(mc.fXTiO2x2,mc.fEnTiO2x2Deposited);
12581   TCanvas *cEnergyloss3=new TCanvas("cEnergyloss3","Energyloss3",
12582                                     0,0,1200,800);
12583   cEnergyloss3->SetFillColor(0);
12584   cEnergyloss3->Divide(2,1);
12585   cEnergyloss3->cd(1);
12586   gXFevsEn->Draw("AP");
12587   gXFevsEn->SetTitle("Energy Loss in Iron");
12588   gXFevsEn->GetXaxis()->SetTitle("Distance from end of track (cm)");
12589   gXFevsEn->GetYaxis()->SetTitle("Energy Loss (MeV)");
12590   gXFevsEn->GetXaxis()->CenterTitle();
12591   gXFevsEn->GetYaxis()->CenterTitle();
12592   gXFevsEn->SetMarkerStyle(3);
12593   gXFevsEn->SetMarkerColor(2);
12594   gXFevsEn->SetMarkerSize(0.8);
12595   gXFevsEn->SetMinimum(0.00001);
12596   gXFevsEn->SetMaximum(50);
12597 
12598   gXScvsEn->Draw("P");
12599   gXScvsEn->SetTitle("Energy Loss in Scintillator");
12600   gXScvsEn->GetXaxis()->SetTitle("Distance from end of track (cm)");
12601   gXScvsEn->GetYaxis()->SetTitle("Energy Loss (MeV)");
12602   gXScvsEn->GetXaxis()->CenterTitle();
12603   gXScvsEn->GetYaxis()->CenterTitle();
12604   gXScvsEn->SetMarkerStyle(3);
12605   gXScvsEn->SetMarkerColor(3);
12606   gXScvsEn->SetMarkerSize(0.8);
12607 
12608   gXAlx2vsEn->Draw("P");
12609   gXAlx2vsEn->SetTitle("Energy Loss in Aluminium");
12610   gXAlx2vsEn->GetXaxis()->SetTitle("Distance from end of track (cm)");
12611   gXAlx2vsEn->GetYaxis()->SetTitle("Energy Loss (MeV)");
12612   gXAlx2vsEn->GetXaxis()->CenterTitle();
12613   gXAlx2vsEn->GetYaxis()->CenterTitle();
12614   gXAlx2vsEn->SetMarkerStyle(3);
12615   gXAlx2vsEn->SetMarkerColor(4);
12616   gXAlx2vsEn->SetMarkerSize(0.8);
12617 
12618   gXTiO2x2vsEn->Draw("P");
12619   gXTiO2x2vsEn->SetTitle("Energy Loss in TiO2");
12620   gXTiO2x2vsEn->GetXaxis()->SetTitle("Distance from end of track (cm)");
12621   gXTiO2x2vsEn->GetYaxis()->SetTitle("Energy Loss (MeV)");
12622   gXTiO2x2vsEn->GetXaxis()->CenterTitle();
12623   gXTiO2x2vsEn->GetYaxis()->CenterTitle();
12624   gXTiO2x2vsEn->SetMarkerStyle(3);
12625   gXTiO2x2vsEn->SetMarkerColor(6);
12626   gXTiO2x2vsEn->SetMarkerSize(0.8);
12627   cEnergyloss3->SetLogy();
12628   
12629   cEnergyloss3->cd(2);
12630   TGraph* gXScvsEn2=TGraphVect(mc.fXSc,mc.fEnScDeposited);
12631   gXScvsEn2->Draw("AP");
12632   gXScvsEn2->SetTitle("Energy Loss in Scintillator");
12633   gXScvsEn2->GetXaxis()->SetTitle("Distance from end of track (cm)");
12634   gXScvsEn2->GetYaxis()->SetTitle("Energy Loss (MeV)");
12635   gXScvsEn2->GetXaxis()->CenterTitle();
12636   gXScvsEn2->GetYaxis()->CenterTitle();
12637   gXScvsEn2->SetMarkerStyle(3);
12638   gXScvsEn2->SetMarkerColor(3);
12639   gXScvsEn2->SetMarkerSize(0.8);
12640 
12641   TGraph* bbFe=TGraphVect(mc.fEn,mc.fdE_dxFe);
12642   //TGraph* bbAl=TGraphVect(mc.fEn,mc.fdE_dxAl);
12643   TGraph* bbSc=TGraphVect(mc.fEn,mc.fdE_dxSc);
12644   TGraph* bbSc2=TGraphVect(mc.fMomGeV,mc.fdE_dxSc);
12645   TGraph* bbSc3=TGraphVect(mc.fMomScGeV,mc.fEnScDeposited);
12646   TGraph* bbMomVsRange=TGraphVect(mc.fXSc,mc.fMomSc);
12647   TCanvas *cBb=new TCanvas("cBb","Bb",0,0,1200,800);
12648   cBb->SetFillColor(0);
12649   cBb->Divide(2,2);
12650   cBb->cd(1);
12651   bbFe->Draw("AP");
12652   bbFe->SetTitle("dE/dx in Iron");
12653   bbFe->GetXaxis()->SetTitle("Particle Energy");
12654   bbFe->GetYaxis()->SetTitle("dE/dx MeV/(g/cm2)");
12655   bbFe->GetXaxis()->CenterTitle();
12656   bbFe->GetYaxis()->CenterTitle();
12657   bbFe->SetMarkerStyle(3);
12658   bbFe->SetMarkerColor(2);
12659   bbFe->SetMarkerSize(0.8);
12660   cBb->cd(2);
12661   bbMomVsRange->Draw("AP");
12662   bbMomVsRange->SetTitle("Muom Momentum vs Range");
12663   bbMomVsRange->GetXaxis()->SetTitle("Range (cm)");
12664   bbMomVsRange->GetYaxis()->SetTitle("Muon Momentum (MeV/c)");
12665   bbMomVsRange->GetXaxis()->CenterTitle();
12666   bbMomVsRange->GetYaxis()->CenterTitle();
12667   bbMomVsRange->SetMarkerStyle(3);
12668   bbMomVsRange->SetMarkerColor(2);
12669   bbMomVsRange->SetMarkerSize(0.8);
12670       /*
12671   bbAl->Draw("AP");
12672   bbAl->SetTitle("dE/dx in Aluminium");
12673   bbAl->GetXaxis()->SetTitle("Particle Energy");
12674   bbAl->GetYaxis()->SetTitle("dE/dx MeV/(g/cm2)");
12675   bbAl->GetXaxis()->CenterTitle();
12676   bbAl->GetYaxis()->CenterTitle();
12677   bbAl->SetMarkerStyle(3);
12678   bbAl->SetMarkerColor(2);
12679   bbAl->SetMarkerSize(0.8);
12680       */
12681   cBb->cd(3);
12682   bbSc->Draw("AP");
12683   bbSc->SetTitle("dE/dx in Scintillator");
12684   bbSc->GetXaxis()->SetTitle("Particle Energy");
12685   bbSc->GetYaxis()->SetTitle("dE/dx MeV/(g/cm2)");
12686   bbSc->GetXaxis()->CenterTitle();
12687   bbSc->GetYaxis()->CenterTitle();
12688   bbSc->SetMarkerStyle(3);
12689   bbSc->SetMarkerColor(2);
12690   bbSc->SetMarkerSize(0.8);
12691   cBb->cd(4);
12692   bbSc2->Draw("AP");
12693   bbSc2->SetTitle("Bethe-Bloch Curve in Scintillator");
12694   bbSc2->GetXaxis()->SetTitle("Muon Momentum");
12695   bbSc2->GetYaxis()->SetTitle("dE/dx MeV/(g/cm2)");
12696   bbSc2->GetXaxis()->CenterTitle();
12697   bbSc2->GetYaxis()->CenterTitle();
12698   bbSc2->SetMarkerStyle(3);
12699   bbSc2->SetMarkerColor(2);
12700   bbSc2->SetMarkerSize(0.8);
12701   bbSc3->Draw("P");
12702   bbSc3->SetMarkerStyle(8);
12703   bbSc3->SetMarkerColor(3);
12704 
12705   this->FlipVector(mc.fXPlanesRatio);
12706   TGraph* eLossRatio=TGraphVect(mc.fXPlanesRatio,mc.fEnRatio);
12707   TCanvas *cELossRatio=new TCanvas("cELossRatio","ELossRatio",
12708                                    0,0,1200,800);
12709   cELossRatio->SetFillColor(0);
12710   eLossRatio->Draw("AP");
12711   eLossRatio->SetTitle("Energy Loss Ratio Fe/Scint");
12712   eLossRatio->GetXaxis()->SetTitle("Distance from end of track (planes)");
12713   eLossRatio->GetYaxis()->SetTitle("Energy Loss Ratio Fe/Scint");
12714   eLossRatio->GetXaxis()->CenterTitle();
12715   eLossRatio->GetYaxis()->CenterTitle();
12716   eLossRatio->SetMarkerStyle(3);
12717   eLossRatio->SetMarkerColor(2);
12718   eLossRatio->SetMarkerSize(0.8);
12719 
12720   if (sum15_18Counter!=0){
12721     MSG("CDAnalysis",Msg::kInfo) 
12722       <<endl
12723       <<" ** Calibration Summary **"<<endl
12724       <<"Sliding Window 15_18:"<<endl
12725       <<"    Total energy dep in scint and Fe="<<sum15_18<<endl
12726       <<"    Av total energy dep in scint and Fe="
12727       <<sum15_18/sum15_18Counter<<" MeV"
12728       <<endl
12729       <<"    Total energy dep in just scint="<<sum15_18Sc<<endl
12730       <<"    Av total energy dep in just scint="
12731       <<sum15_18Sc/sum15_18Counter<<" MeV"
12732       <<endl;
12733   }
12734 
12735   Double_t totPlanesHit=mc.GetTotalNumScPlanesHit();
12736   MSG("CDAnalysis",Msg::kInfo) 
12737     <<"Total number planes hit="<<totPlanesHit<<endl;
12738 }
12739 
12740 //......................................................................
12741  
12742 void CDAnalysis::BbVsGminos()
12743 {
12744   //create simpleMC object
12745   CDSimpleMC mc;
12746   //run mc
12747   mc.RunMC();
12748 
12749   Float_t sum15_18=0;
12750   Float_t sum15_18Sc=0;
12751   Float_t sum15_18NotSc=0;
12752   Float_t sum15_18All=0;
12753   Float_t sum15_18ScGminos=0;
12754   Float_t sum15_18NotScGminos=0;
12755   Float_t sum15_18AllGminos=0;
12756   Float_t sum15_18Counter=0;
12757   vector<Double_t> eDepositedPl;
12758 
12759   vector<Double_t> tempEnDep(60,0);
12760   vector<Double_t> tempEnDepNotSc(60,0);
12761   vector<Double_t> tempNumDsh(60,0);
12762   vector<Double_t> tempNum(60,0);
12763   vector<TH1F*> hEnDepNotSc;
12764 
12765   for (Int_t pl=0;pl<60;pl++){
12766     fS="Energy Deposition in Iron, plane=";
12767     string sPl=Form("%d",pl);
12768     fS+=sPl;
12769     hEnDepNotSc.push_back(new TH1F(fS.c_str(),fS.c_str(),600,-2,200));
12770     hEnDepNotSc[pl]->SetBit(TH1::kCanRebin);
12771   }
12772 
12776 
12777   this->InitialiseLoopVariables();  
12778   
12779   for(Int_t event=0;event<fEvents;event++){
12780     
12781     this->SetLoopVariables(event);
12782 
12783     //cut on not straight tracks
12784     Double_t mainX1Cut=0.5;
12785     if (!this->IsStraightTrack(mainX1Cut)){
12786       continue;
12787     }
12788 
12789     for (Int_t p=0;p<60;p++){
12790       Double_t enDep=this->TrueEnDep(p,event);
12791       Double_t enDepNotSc=this->TrueEnDepNotSc(p,event);
12792       Int_t numDsh=this->TrueNumDigiScintHits(p,event);
12793       //const Double_t latestT2=hitInfo->GetLatestT2();
12794       //fill the histo
12795       hEnDepNotSc[p]->Fill(1000*enDepNotSc);
12796       
12797       MSG("CDAnalysis",Msg::kVerbose) 
12798         <<", eDepNotSc="<<1000*enDepNotSc<<endl;
12799       
12800       //I'm not averaging zeros here - this is wrong!
12801       if (enDep>0 && enDepNotSc>0){
12802         tempEnDep[p]+=enDep;
12803         tempEnDepNotSc[p]+=enDepNotSc;
12804         tempNumDsh[p]+=numDsh;
12805         tempNum[p]++;
12806       }
12807     }
12808   }//end of for                                       
12809   
12813 
12814   TCanvas *cEnDep=new TCanvas("cEnDep","EnDep",0,0,1200,800);
12815   cEnDep->SetFillColor(0);
12816   cEnDep->Divide(2,3);
12817   cEnDep->cd(1);
12818   hEnDepNotSc[0]->Draw();
12819   cEnDep->cd(2);
12820   hEnDepNotSc[1]->Draw();
12821   cEnDep->cd(3);
12822   hEnDepNotSc[2]->Draw();
12823   cEnDep->cd(4);
12824   hEnDepNotSc[3]->Draw();
12825   cEnDep->cd(5);
12826   hEnDepNotSc[4]->Draw();
12827   cEnDep->cd(6);
12828   hEnDepNotSc[5]->Draw();
12829 
12830   vector<Double_t> eScGminos(60,0);
12831   vector<Double_t> eNotScGminos(60,0);
12832   vector<Double_t> numDshScGminos(60,0);
12833   vector<Double_t> xScGminos(60,0);
12834   Double_t totalEnDep=0;
12835 
12836   for (Int_t p=0;p<60;p++){
12837     if (tempNum[p]>0){
12838       eScGminos[p]=1000.*tempEnDep[p]/tempNum[p];
12839       eNotScGminos[p]=1000.*tempEnDepNotSc[p]/tempNum[p];
12840       numDshScGminos[p]=tempNumDsh[p]/tempNum[p];
12841     }
12842     xScGminos[p]=p;
12843 
12844     //keep a running total
12845     totalEnDep+=eScGminos[p]+eNotScGminos[p];
12846 
12847     MSG("CDAnalysis",Msg::kInfo) 
12848       <<"plane="<<xScGminos[p]
12849       <<", enDep="<<eScGminos[p]
12850       <<", enDepNotSc="<<eNotScGminos[p]
12851       <<", totalEnDep="<<totalEnDep<<endl;
12852   }
12853 
12855   //section for sliding window
12857   
12858   vector<TProfile*> pSigCorVsDist;
12859   vector<Int_t> vWindowSize;
12860   vector<Float_t> bigAv;
12861   vector<Int_t> bigAvCounter;
12862   Int_t minEventLength=40;
12863 
12864   //need a new vector for this!!!!
12867   MSG("CDAnalysis",Msg::kInfo) 
12868     <<"size="<<mc.fEnScDeposited.size()<<endl;
12869 
12870   //initialise the profile histos
12871   for (Int_t p=20;p>1;p--){
12872     vWindowSize.push_back(p);
12873     bigAv.push_back(0);
12874     bigAvCounter.push_back(0);
12875   }
12876   
12877   for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
12878        windowSize!=vWindowSize.end();++windowSize){
12879     
12880     string sName=Form("%d",*windowSize);
12881     pSigCorVsDist.push_back
12882       (new TProfile(("pSigCorVsDist"+sName).c_str(),
12883                     ("pSigCorVsDist"+sName).c_str(),100,-2,40));
12884   }
12885 
12886   vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
12887   vector<Float_t>::iterator av=bigAv.begin();
12888   vector<Int_t>::iterator count=bigAvCounter.begin();
12889   
12890   //loop over the different window sizes
12891   for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
12892        windowSize!=vWindowSize.end();++windowSize){
12893     MSG("CDAnalysis",Msg::kDebug)
12894       <<"Window size="<<*windowSize<<endl;
12895  
12896     //slide the window along from the end to 40-windowSize
12897     for (Int_t p=0;p<minEventLength-*windowSize;p++){
12898       Int_t lastPlane=mc.fEnScDeposited.size()-1;
12899       Int_t windowStart=lastPlane-p;
12900 
12901       //loop through the hits in the window      
12902       for (Int_t i=0;i<*windowSize;i++){
12903         Int_t plane=windowStart-i;
12904         
12905         (*prof)->Fill(p,mc.fEnScDeposited[plane]);
12906         (*av)+=mc.fEnScDeposited[plane];
12907         (*count)++;
12908 
12909         //calculate the best window value
12910         if (*windowSize==15 && windowStart==lastPlane-18){
12911           //BB
12912           sum15_18+=mc.fEnDepositedPl[plane];
12913           sum15_18Sc+=mc.fEnScDeposited[plane];
12914           sum15_18NotSc+=mc.fEnNotScDeposited[plane];
12915           sum15_18All+=mc.fEnScDeposited[plane]+
12916             mc.fEnNotScDeposited[plane];
12917 
12918           //gminos
12919           sum15_18ScGminos+=eScGminos[plane];
12920           sum15_18NotScGminos+=eNotScGminos[plane];
12921           sum15_18AllGminos+=eScGminos[plane]+eNotScGminos[plane];
12922 
12923           //general counter
12924           sum15_18Counter++;
12925         }
12926       }
12927     }
12928     av++;
12929     count++;
12930     prof++;
12931   }
12932 
12933   //turn on the stats box printing
12934   gStyle->SetOptStat(11);
12935 
12936   TCanvas *cProf=new TCanvas("cProf","Prof",0,0,1200,800);
12937   cProf->SetFillColor(0);
12938   string sName="SlidingWindowBB.ps";
12939   cProf->Print((sName+"[").c_str());
12940   gErrorIgnoreLevel=1;
12941   //plot the unnormalised prof first
12942   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
12943        prof!=pSigCorVsDist.end();++prof){      
12944     cProf->Clear();
12945     (*prof)->Draw();
12946     (*prof)->SetTitle("Energy Deposited in Sliding Window");
12947     (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
12948     (*prof)->GetYaxis()->SetTitle("Energy Deposited (MeV)");
12949     (*prof)->GetXaxis()->CenterTitle();
12950     (*prof)->GetYaxis()->CenterTitle();
12951     cProf->Print(sName.c_str());
12952   }
12953 
12954   //now normalise the prof
12955   av=bigAv.begin();
12956   count=bigAvCounter.begin();
12957   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
12958        prof!=pSigCorVsDist.end();++prof){
12959       
12960     //normalise the prof and scale the axes
12961     MSG("CDAnalysis",Msg::kInfo)
12962       <<"bigCounter="<<*count<<", bigAv="<<*av<<endl;
12963     if (*av>0) (*prof)->Scale((*count)/(*av));
12964     (*prof)->SetMaximum(1.2);
12965     (*prof)->SetMinimum(0.8);
12966       
12967     cProf->Clear();
12968     (*prof)->Draw();
12969     (*prof)->SetTitle("Normalised Energy Deposited in Sliding Window");
12970     (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
12971     (*prof)->GetYaxis()->SetTitle("Normalised Energy Deposited");
12972     (*prof)->GetXaxis()->CenterTitle();
12973     (*prof)->GetYaxis()->CenterTitle();
12974     cProf->Print(sName.c_str());
12975     av++;
12976     count++;
12977   }
12978   //close the file
12979   gErrorIgnoreLevel=0;
12980   cProf->Print((sName+"]").c_str());
12981 
12982   TLegend *legend = new TLegend(0.85, 0.7, 0.9, 0.9);
12983   legend->SetBorderSize(0);
12984   legend->SetFillColor(0);
12985   legend->SetTextSize(0.035);
12986 
12987   //now do a few profs on the same plot
12988   TCanvas *cProf2=new TCanvas("cProf2","Prof",0,0,1200,800);
12989   cProf2->SetFillColor(0);
12990   sName="SlidingWindowAll.ps";
12991   //cProf2->Print((sName+"[").c_str());
12992   Int_t counter=0;
12993   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
12994        prof!=pSigCorVsDist.end();++prof){
12995 
12996     (*prof)->SetMaximum(1.09);
12997     (*prof)->SetMinimum(0.96);
12998 
12999     //count which prof got to
13000     counter++;
13001 
13002     //decide which profs to draw
13003     static Bool_t firstTime=true;
13004     if (counter==1 || counter==6 || counter==11){ 
13005       if (firstTime) {
13006         (*prof)->Draw();
13007         firstTime=false;
13008       }
13009       else  (*prof)->Draw("sames");
13010 
13011       (*prof)->SetTitle("Normalised Energy Deposited in Sliding Window");
13012       (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
13013       (*prof)->GetYaxis()->SetTitle("Normalised Energy Deposition");
13014       (*prof)->GetXaxis()->CenterTitle();
13015       (*prof)->GetYaxis()->CenterTitle();
13016       static Int_t color=2;
13017       (*prof)->SetLineColor(color);
13018       color+=2;
13019       string sWindowSize=Form("%d",21-counter);
13020       string sGraph=" Window size = ";
13021       sGraph+=sWindowSize;
13022       sGraph+=" planes";
13023       legend->AddEntry((*prof),sGraph.c_str(),"l");
13024     }
13025   }
13026   legend->Draw();
13027 
13028   //get the graphs
13029   TGraph* gScBb=TGraphVect(mc.fXScPlanes,mc.fEnScDeposited);
13030   TGraph* gScGminos=TGraphVect(xScGminos,eScGminos);
13031   TGraph* gNumDshScGminos=TGraphVect(xScGminos,numDshScGminos);
13032   
13033   //get canvas
13034   TCanvas *cBbVsGminos=new TCanvas("cBbVsGminos","BbVsGminos",
13035                                    0,0,1200,800);
13036   cBbVsGminos->SetFillColor(0);
13037   cBbVsGminos->Divide(1,3);
13038   cBbVsGminos->cd(1);
13039   gScBb->Draw("AP");
13040   gScBb->SetTitle("Energy Loss in Simple BB MC");
13041   gScBb->GetXaxis()->SetTitle("Plane");
13042   gScBb->GetYaxis()->SetTitle("Energy Loss (MeV)");
13043   gScBb->GetXaxis()->CenterTitle();
13044   gScBb->GetYaxis()->CenterTitle();
13045   gScBb->SetMarkerStyle(3);
13046   gScBb->SetMarkerColor(2);
13047   gScBb->SetMarkerSize(0.8);
13048   cBbVsGminos->cd(2);
13049   gScGminos->Draw("AP");
13050   gScGminos->SetTitle("Energy Loss in GMINOS");
13051   gScGminos->GetXaxis()->SetTitle("Plane");
13052   gScGminos->GetYaxis()->SetTitle("Energy Loss (MeV)");
13053   gScGminos->GetXaxis()->CenterTitle();
13054   gScGminos->GetYaxis()->CenterTitle();
13055   gScGminos->SetMarkerStyle(3);
13056   gScGminos->SetMarkerColor(2);
13057   gScGminos->SetMarkerSize(0.8);
13058   cBbVsGminos->cd(3);
13059   gNumDshScGminos->Draw("AP");
13060   gNumDshScGminos->SetTitle("Num DigiScintHits in GMINOS");
13061   gNumDshScGminos->GetXaxis()->SetTitle("Plane");
13062   gNumDshScGminos->GetYaxis()->SetTitle("Num DigiScintHits");
13063   gNumDshScGminos->GetXaxis()->CenterTitle();
13064   gNumDshScGminos->GetYaxis()->CenterTitle();
13065   gNumDshScGminos->SetMarkerStyle(3);
13066   gNumDshScGminos->SetMarkerColor(2);
13067   gNumDshScGminos->SetMarkerSize(0.8);
13068 
13069   //new graph
13070   TGraph* gNotScBb=TGraphVect(mc.fXNotScPlanes,mc.fEnNotScDeposited);
13071   TGraph* gFeBb=TGraphVect(mc.fXFePlanes,mc.fEnFeDeposited);
13072   TGraph* gNotScGminos=TGraphVect(xScGminos,eNotScGminos);
13073   TCanvas *cBbVsGminos2=new TCanvas("cBbVsGminos2","BbVsGminos2",
13074                                     0,0,1200,800);
13075   cBbVsGminos2->SetFillColor(0);
13076   cBbVsGminos2->Divide(1,2);
13077   cBbVsGminos2->cd(1);
13078   gNotScBb->Draw("AP");
13079   gNotScBb->SetTitle("Energy Loss in Non-Acive Material in BB");
13080   gNotScBb->GetXaxis()->SetTitle("Plane");
13081   gNotScBb->GetYaxis()->SetTitle("Energy Loss (MeV)");
13082   gNotScBb->GetXaxis()->CenterTitle();
13083   gNotScBb->GetYaxis()->CenterTitle();
13084   gNotScBb->SetMarkerStyle(3);
13085   gNotScBb->SetMarkerColor(2);
13086   gNotScBb->SetMarkerSize(0.8);
13087   gFeBb->Draw("P");
13088   gFeBb->SetMarkerStyle(3);
13089   gFeBb->SetMarkerColor(3);
13090   gFeBb->SetMarkerSize(0.8);
13091   cBbVsGminos2->cd(2);
13092   gNotScGminos->Draw("AP");
13093   gNotScGminos->SetTitle("Energy Loss in Non-Acive Material in GMINOS");
13094   gNotScGminos->GetXaxis()->SetTitle("Plane");
13095   gNotScGminos->GetYaxis()->SetTitle("Energy Loss (MeV)");
13096   gNotScGminos->GetXaxis()->CenterTitle();
13097   gNotScGminos->GetYaxis()->CenterTitle();
13098   gNotScGminos->SetMarkerStyle(3);
13099   gNotScGminos->SetMarkerColor(2);
13100   gNotScGminos->SetMarkerSize(0.8);
13101 
13102   //new graph
13103   this->FlipVector(mc.fXScPlanes);
13104   TGraph* eLossSc=TGraphVect(mc.fXScPlanes,mc.fEnScDeposited);
13105   TCanvas *cELossSc=new TCanvas("cELossSc","ELossSc",
13106                                    0,0,1200,800);
13107   cELossSc->SetFillColor(0);
13108   eLossSc->Draw("AP");
13109   eLossSc->SetTitle("Energy Loss in Scintillator");
13110   eLossSc->GetXaxis()->SetTitle("Distance from end of track (planes)");
13111   eLossSc->GetYaxis()->SetTitle("Energy Loss (MeV)");
13112   eLossSc->GetXaxis()->CenterTitle();
13113   eLossSc->GetYaxis()->CenterTitle();
13114   eLossSc->SetMarkerStyle(3);
13115   eLossSc->SetMarkerColor(2);
13116   eLossSc->SetMarkerSize(0.8);
13117 
13118   this->FlipVector(mc.fX);
13119   TGraph* energyLoss=TGraphVect(mc.fX,mc.fEnDeposited);
13120   TCanvas *cEnergyLoss=new TCanvas("cEnergyLoss","EnergyLoss",
13121                                    0,0,1200,800);
13122   cEnergyLoss->SetFillColor(0);
13123   energyLoss->Draw("AP");
13124   energyLoss->SetTitle("Energy Loss in Scintillator and Iron");
13125   energyLoss->GetXaxis()->SetTitle("Distance from end of track (cm)");
13126   energyLoss->GetYaxis()->SetTitle("Energy Loss (MeV)");
13127   energyLoss->GetXaxis()->CenterTitle();
13128   energyLoss->GetYaxis()->CenterTitle();
13129   energyLoss->SetMarkerStyle(3);
13130   energyLoss->SetMarkerColor(2);
13131   energyLoss->SetMarkerSize(0.8);
13132 
13133   this->FlipVector(mc.fXPlanes);
13134   TGraph* energyloss2=TGraphVect(mc.fXPlanes,mc.fEnDeposited);
13135   TCanvas *cEnergyloss2=new TCanvas("cEnergyloss2","Energyloss2",
13136                                    0,0,1200,800);
13137   cEnergyloss2->SetFillColor(0);
13138   energyloss2->Draw("AP");
13139   energyloss2->SetTitle("Energy Loss in Scintillator and Iron");
13140   energyloss2->GetXaxis()->SetTitle("Distance from end of track (planes)");
13141   energyloss2->GetYaxis()->SetTitle("Energy Loss (MeV)");
13142   energyloss2->GetXaxis()->CenterTitle();
13143   energyloss2->GetYaxis()->CenterTitle();
13144   energyloss2->SetMarkerStyle(3);
13145   energyloss2->SetMarkerColor(2);
13146   energyloss2->SetMarkerSize(0.8);
13147   
13148   TGraph* bb=TGraphVect(mc.fEn,mc.fdE_dxFe);
13149   TCanvas *cBb=new TCanvas("cBb","Bb",0,0,1200,800);
13150   cBb->SetFillColor(0);
13151   bb->Draw("AP");
13152   bb->SetMarkerStyle(3);
13153   bb->SetMarkerColor(2);
13154   bb->SetMarkerSize(0.8);
13155 
13156   if (sum15_18Counter!=0){
13157     MSG("CDAnalysis",Msg::kInfo) 
13158       <<endl
13159       <<" ** Calibration Summary **"<<endl
13160       <<"Total number of planes hit in BB="<<mc.GetTotalNumScPlanesHit()
13161       <<endl
13162       <<"Sliding Window 15_18:"<<endl
13163       <<"BB Steel and Scintillator:"<<endl
13164       <<"    Total energy dep="<<sum15_18<<" MeV"<<endl
13165       <<"    Av energy dep="<<sum15_18/sum15_18Counter
13166       <<" MeV"<<endl
13167       <<"GMINOS:"<<endl
13168       <<"    Total energy dep="<<"?"<<" MeV"<<endl
13169       <<"    Av energy dep="<<"?"
13170       <<" MeV"<<endl
13171       <<endl<<endl
13172       <<"BB Non-Active Material:"<<endl
13173       <<"    Total energy dep="<<sum15_18NotSc<<" MeV"<<endl
13174       <<"    Av energy dep="<<sum15_18NotSc/sum15_18Counter
13175       <<" MeV"<<endl
13176       <<"GMINOS:"<<endl
13177       <<"    Total energy dep="<<sum15_18NotScGminos<<" MeV"<<endl
13178       <<"    Av energy dep="<<sum15_18NotScGminos/sum15_18Counter
13179       <<" MeV ("<<100*(sum15_18NotScGminos-sum15_18NotSc)/sum15_18NotSc
13180       <<"%)"<<endl
13181       <<endl<<endl
13182       <<"BB Just Scintillator:"<<endl
13183       <<"    Total energy dep="<<sum15_18Sc<<" MeV"<<endl
13184       <<"    Av energy dep="<<sum15_18Sc/sum15_18Counter
13185       <<" MeV"<<endl
13186       <<"GMINOS:"<<endl
13187       <<"    Total energy dep="<<sum15_18ScGminos<<" MeV"<<endl
13188       <<"    Av energy dep="<<sum15_18ScGminos/sum15_18Counter
13189       <<" MeV ("<<100*(sum15_18ScGminos-sum15_18Sc)/sum15_18Sc<<"%)"
13190       <<endl
13191       <<endl<<endl
13192       <<"BB Total (Active+Passive):"<<endl
13193       <<"    Total energy dep="<<sum15_18All<<" MeV"<<endl
13194       <<"    Av energy dep="<<sum15_18All/sum15_18Counter
13195       <<" MeV"<<endl
13196       <<"GMINOS:"<<endl
13197       <<"    Total energy dep="<<sum15_18AllGminos<<" MeV"<<endl
13198       <<"    Av energy dep="<<sum15_18AllGminos/sum15_18Counter
13199       <<" MeV ("<<100*(sum15_18AllGminos-sum15_18All)/sum15_18All<<"%)"
13200       <<endl<<endl; 
13201   }
13202 }
13203 
13204 //......................................................................
13205 
13206 //just a simple function for use with ROOT's TF1
13207 Double_t FitFunc(Double_t *x,Double_t *par)
13208 {
13209   return par[0]*pow(x[0],par[1])+par[2];
13210 }
13211 
13212 //......................................................................
13213  
13214 void CDAnalysis::BbThkFeVsRange() const
13215 {
13216   //create simpleMC object
13217   CDSimpleMC mc;
13218 
13219   vector<Double_t> vPlanesHit;
13220   vector<Double_t> vThkFe;
13221 
13222   //loop over the different energies
13223   for (Double_t thkFe=2.4;thkFe<2.6;thkFe+=0.01){
13224     MSG("CDAnalysis",Msg::kInfo) 
13225       <<"thkFe="<<thkFe<<endl;
13226     
13227     //set up and run the MC
13228     mc.SetThkFe(thkFe);
13229     mc.RunMC();
13230     
13231     //fill the vectors
13232     vThkFe.push_back(mc.GetThkFe());
13233     vPlanesHit.push_back(mc.GetTotalNumScPlanesHit());
13234   }
13235 
13236   TGraph* gThkFeVsRange=TGraphVect(vPlanesHit,vThkFe);
13237   TCanvas *cThkFeVsRange=new TCanvas("cThkFeVsRange","ThkFeVsRange",
13238                                      0,0,1200,800);
13239   cThkFeVsRange->SetFillColor(0);
13240   gThkFeVsRange->Draw("AP");
13241   gThkFeVsRange->SetTitle("Iron Thickness Vs Range");
13242   gThkFeVsRange->GetXaxis()->SetTitle("Range (planes)");
13243   gThkFeVsRange->GetYaxis()->SetTitle("Fe Thk (cm)");
13244   gThkFeVsRange->GetXaxis()->CenterTitle();
13245   gThkFeVsRange->GetYaxis()->CenterTitle();
13246   gThkFeVsRange->SetMarkerStyle(3);
13247   gThkFeVsRange->SetMarkerColor(2);
13248   gThkFeVsRange->SetMarkerSize(0.8);
13249 }
13250 
13251 //......................................................................
13252  
13253 void CDAnalysis::BbEnVsRange() const
13254 {
13255   //create simpleMC object
13256   CDSimpleMC mc;
13257 
13258   vector<Double_t> lastPlane;
13259   vector<Double_t> energyBeam;
13260   vector<Double_t> sumEnDepSc;
13261   vector<Double_t> ratioScToBeam;
13262 
13263   //loop over the different energies
13264   for (Int_t beamP=1400;beamP<2010;beamP+=10){
13265     MSG("CDAnalysis",Msg::kInfo) 
13266       <<"Beam P="<<beamP<<endl;
13267     
13268     //set up and run the MC
13269     mc.SetParticleMomentum(beamP);
13270     mc.RunMC();
13271     
13272     //fill the vectors
13273     energyBeam.push_back(mc.GetParticleEnergy());
13274     lastPlane.push_back(mc.GetTotalNumScPlanesHit());
13275     sumEnDepSc.push_back(mc.GetTotalScEnLoss());
13276     ratioScToBeam.push_back(mc.GetTotalScEnLoss()/
13277                             mc.GetParticleEnergy());
13278   }
13279 
13280   MSG("CDAnalysis",Msg::kDebug)
13281     <<"Vpl size="<<lastPlane.size()
13282     <<", Ven size="<<energyBeam.size()<<endl;
13283   TGraph* gEnBeamVsRange=TGraphVect(lastPlane,energyBeam);
13284   TCanvas *cEnBeamVsRange=new TCanvas("cEnBeamVsRange","EnBeamVsRange",
13285                                    0,0,1200,800);
13286   cEnBeamVsRange->SetFillColor(0);
13287   gEnBeamVsRange->Draw("AP");
13288   gEnBeamVsRange->SetTitle("Energy Vs Range");
13289   gEnBeamVsRange->GetXaxis()->SetTitle("Range (planes)");
13290   gEnBeamVsRange->GetYaxis()->SetTitle("Beam Energy");
13291   gEnBeamVsRange->GetXaxis()->CenterTitle();
13292   gEnBeamVsRange->GetYaxis()->CenterTitle();
13293   gEnBeamVsRange->SetMarkerStyle(3);
13294   gEnBeamVsRange->SetMarkerColor(2);
13295   gEnBeamVsRange->SetMarkerSize(0.8);
13296 
13297   TGraph* gScToBeamVsBeam=TGraphVect(energyBeam,ratioScToBeam);
13298   TCanvas *cScToBeamVsBeam=new TCanvas("cScToBeamVsBeam",
13299                                        "cScToBeamVsBeam",
13300                                        0,0,1200,800);
13301   cScToBeamVsBeam->SetFillColor(0);
13302   gScToBeamVsBeam->Draw("AP");
13303   gScToBeamVsBeam->SetTitle("Ratio Sc to Beam Energy vs Beam Energy");
13304   gScToBeamVsBeam->GetXaxis()->SetTitle("Beam Energy");
13305   gScToBeamVsBeam->GetYaxis()->SetTitle("Ratio Sc to Beam Energy");
13306   gScToBeamVsBeam->GetXaxis()->CenterTitle();
13307   gScToBeamVsBeam->GetYaxis()->CenterTitle();
13308   gScToBeamVsBeam->SetMarkerStyle(3);
13309   gScToBeamVsBeam->SetMarkerColor(2);
13310   gScToBeamVsBeam->SetMarkerSize(0.8);
13311 
13312   vector<Double_t> enRange;
13313   vector<Double_t> gradient;
13314 
13315   MSG("CDAnalysis",Msg::kInfo)
13316     <<"First fit..."<<endl;
13317   for (vector<Double_t>::iterator r=lastPlane.begin();
13318        r!=lastPlane.end()-3;++r){
13319     //for (Float_t fitRangeMin=lastPlane[0];
13320     // fitRangeMin<lastPlane[lastPlane.size()-3]-1;fitRangeMin++){
13321     static Int_t counter=0;
13322     
13323     gEnBeamVsRange->Fit("pol1","q","",*r,1000);
13324     TF1* func=gEnBeamVsRange->GetFunction("pol1");
13325     Double_t funcM=func->GetParameter(1);
13326     MSG("CDAnalysis",Msg::kInfo)
13327       <<"fitMin="<<*r<<", en="<<energyBeam[counter]
13328       <<", m="<<funcM<<endl;
13329 
13330     enRange.push_back(energyBeam[counter]);
13331     gradient.push_back(funcM);
13332 
13333     counter++;
13334   }
13335 
13336   //now fit to a non-straight line
13337   TF1 *form = new TF1("form",FitFunc,0,70,3);
13338   //par[0]*TMath::Power(x[0],par[1]) + par[2];
13339   form->SetParameters(1,1,0);
13340   gEnBeamVsRange->Fit("form","q");
13341 
13342   TGraph* gFitGradVsRange=TGraphVect(enRange,gradient);
13343   TCanvas *cFitGradVsRange=new TCanvas("cFitGradVsRange",
13344                                        "FitGradVsRange",
13345                                        0,0,1200,800);
13346   cFitGradVsRange->SetFillColor(0);
13347   gFitGradVsRange->Draw("AP");
13348   gFitGradVsRange->SetTitle("Fit Gradient Vs Min Beam Energy in Fit");
13349   gFitGradVsRange->GetXaxis()->SetTitle("Min Beam Energy in Fit");
13350   gFitGradVsRange->GetYaxis()->SetTitle("Gradient of EnVsRange");
13351   gFitGradVsRange->GetXaxis()->CenterTitle();
13352   gFitGradVsRange->GetYaxis()->CenterTitle();
13353   gFitGradVsRange->SetMarkerStyle(3);
13354   gFitGradVsRange->SetMarkerColor(2);
13355   gFitGradVsRange->SetMarkerSize(0.8);
13356 
13357   //now plot the normalised one
13358   this->NormaliseVector(gradient);
13359   TGraph* gNormFitGradVsRange=TGraphVect(enRange,gradient);
13360   TCanvas *cNormFitGradVsRange=new TCanvas("cNormFitGradVsRange",
13361                                        "NormFitGradVsRange",
13362                                        0,0,1200,800);
13363   cNormFitGradVsRange->SetFillColor(0);
13364   gNormFitGradVsRange->Draw("AP");
13365   gNormFitGradVsRange->SetTitle("Fit Gradient Vs Min Beam Energy in Fit");
13366   gNormFitGradVsRange->GetXaxis()->SetTitle("Min Beam Energy in Fit");
13367   gNormFitGradVsRange->GetYaxis()->SetTitle("Gradient of EnVsRange");
13368   gNormFitGradVsRange->GetXaxis()->CenterTitle();
13369   gNormFitGradVsRange->GetYaxis()->CenterTitle();
13370   gNormFitGradVsRange->SetMarkerStyle(3);
13371   gNormFitGradVsRange->SetMarkerColor(2);
13372   gNormFitGradVsRange->SetMarkerSize(0.8);
13373 
13374   MSG("CDAnalysis",Msg::kDebug)
13375     <<"Vpl size="<<lastPlane.size()
13376     <<", Ven size="<<sumEnDepSc.size()<<endl;
13377   TGraph* gEnDepScVsRange=TGraphVect(lastPlane,sumEnDepSc);
13378   TCanvas *cEnDepScVsRange=new TCanvas("cEnDepScVsRange",
13379                                        "EnDepScVsRange",0,0,1200,800);
13380   cEnDepScVsRange->SetFillColor(0);
13381   gEnDepScVsRange->Draw("AP");
13382   gEnDepScVsRange->SetTitle("Energy Vs Range");
13383   gEnDepScVsRange->GetXaxis()->SetTitle("Range (planes)");
13384   gEnDepScVsRange->GetYaxis()->SetTitle("Energy Deposited in Sc (MeV)");
13385   gEnDepScVsRange->GetXaxis()->CenterTitle();
13386   gEnDepScVsRange->GetYaxis()->CenterTitle();
13387   gEnDepScVsRange->SetMarkerStyle(3);
13388   gEnDepScVsRange->SetMarkerColor(2);
13389   gEnDepScVsRange->SetMarkerSize(0.8);
13390 
13391   vector<Double_t> enRange2;
13392   vector<Double_t> gradient2;
13393 
13394   MSG("CDAnalysis",Msg::kInfo)
13395     <<"Second fit..."<<endl;
13396   for (vector<Double_t>::iterator r=lastPlane.begin();
13397        r!=lastPlane.end()-3;++r){
13398     //for (Float_t fitRangeMin=lastPlane[0];
13399     // fitRangeMin<lastPlane[lastPlane.size()-3]-1;fitRangeMin++){
13400     static Int_t counter=0;
13401     
13402     gEnDepScVsRange->Fit("pol1","q","",*r,1000);
13403     TF1* func=gEnDepScVsRange->GetFunction("pol1");
13404     Double_t funcM=func->GetParameter(1);
13405     MSG("CDAnalysis",Msg::kInfo)
13406       <<"fitMin="<<*r
13407       <<", m="<<funcM<<endl;
13408 
13409     enRange2.push_back(sumEnDepSc[counter]);
13410     gradient2.push_back(funcM);
13411 
13412     counter++;
13413   }
13414   MSG("CDAnalysis",Msg::kInfo)
13415     <<"Finished second fit..."<<endl;
13416 
13417   TGraph* gFitGradVsRange2=TGraphVect(enRange2,gradient2);
13418   TCanvas *cFitGradVsRange2=new TCanvas("cFitGradVsRange2",
13419                                        "FitGradVsRange2",
13420                                        0,0,1200,800);
13421   cFitGradVsRange2->SetFillColor(0);
13422   gFitGradVsRange2->Draw("AP");
13423   gFitGradVsRange2->SetTitle("Norm Fit Gradient Vs Min Energy Dep Sc in Fit");
13424   gFitGradVsRange2->GetXaxis()->SetTitle("Min Energy Dep Sc in Fit");
13425   gFitGradVsRange2->GetYaxis()->SetTitle("Gradient of EnDepScVsRange");
13426   gFitGradVsRange2->GetXaxis()->CenterTitle();
13427   gFitGradVsRange2->GetYaxis()->CenterTitle();
13428   gFitGradVsRange2->SetMarkerStyle(3);
13429   gFitGradVsRange2->SetMarkerColor(2);
13430   gFitGradVsRange2->SetMarkerSize(0.8);
13431 
13432   MSG("CDAnalysis",Msg::kInfo)
13433     <<"Plotting normalised one..."<<endl;
13434 
13435   //now plot the normalised one
13436   this->NormaliseVector(gradient2);
13437   TGraph* gNormFitGradVsRange2=TGraphVect(enRange2,gradient2);
13438   TCanvas *cNormFitGradVsRange2=new TCanvas("cNormFitGradVsRange2",
13439                                        "NormFitGradVsRange2",
13440                                        0,0,1200,800);
13441   cNormFitGradVsRange2->SetFillColor(0);
13442   gNormFitGradVsRange2->Draw("AP");
13443   gNormFitGradVsRange2->SetTitle("Norm Fit Gradient Vs Min Energy Dep Sc in Fit");
13444   gNormFitGradVsRange2->GetXaxis()->SetTitle("Min Energy Dep Sc in Fit");
13445   gNormFitGradVsRange2->GetYaxis()->SetTitle("Gradient of EnDepScVsRange");
13446   gNormFitGradVsRange2->GetXaxis()->CenterTitle();
13447   gNormFitGradVsRange2->GetYaxis()->CenterTitle();
13448   gNormFitGradVsRange2->SetMarkerStyle(3);
13449   gNormFitGradVsRange2->SetMarkerColor(2);
13450   gNormFitGradVsRange2->SetMarkerSize(0.8);
13451 
13452   TF1 *form2 = new TF1("form2",FitFunc,0,70,3);
13453   form2->SetParameters(1,1,0);
13454   form2->FixParameter(2,0);
13455   //gEnDepScVsRange->Fit("form2","q");
13456 }
13457 
13458 //......................................................................
13459 
13460 void CDAnalysis::DrawResponsePlot(string& title,TProfile* prof,
13461                                   TProfile* profX,TProfile* profT,
13462                                   const std::map<Int_t,Float_t>& num,
13463                                   const std::map<Int_t,Float_t>& numX,
13464                                   const std::map<Int_t,Float_t>& numT,
13465                                   string sXTitle) const
13466 {
13467 
13468   TLegend *legend = new TLegend(0.85, 0.7, 0.9, 0.9);
13469   legend->SetBorderSize(0);
13470   legend->SetFillColor(0);
13471   legend->SetTextSize(0.035);
13472   string sGraph="Tracked hits";
13473   legend->AddEntry(prof,sGraph.c_str(),"p");
13474   sGraph="Untracked hits";
13475   legend->AddEntry(profX,sGraph.c_str(),"p");
13476   sGraph="All hits";
13477   legend->AddEntry(profT,sGraph.c_str(),"p");
13478 
13479   //default x axis title
13480   if (sXTitle=="") sXTitle="Plane";
13481 
13482   //make the graphs
13483   TGraph* gNum=this->TGraphMap(num);
13484   TGraph* gNumX=this->TGraphMap(numX);
13485   TGraph* gNumT=this->TGraphMap(numT);
13486 
13487   //create the canvas and plot
13488   TCanvas *cResponse=new TCanvas(title.c_str(),title.c_str(),
13489                                  0,0,1200,800);
13490   cResponse->SetFillColor(0);
13491   cResponse->Divide(1,2);
13492   cResponse->cd(1);
13493   prof->Draw("AP");
13494   prof->SetTitle(title.c_str());
13495   prof->GetXaxis()->SetTitle(sXTitle.c_str());
13496   prof->GetYaxis()->SetTitle("Average SigCor");
13497   prof->GetXaxis()->CenterTitle();
13498   prof->GetYaxis()->CenterTitle();
13499   prof->SetMarkerStyle(3);
13500   prof->SetMarkerColor(2);
13501   prof->SetMarkerSize(0.8);
13502   profX->Draw("same");
13503   profX->SetMarkerStyle(3);
13504   profX->SetMarkerColor(3);
13505   profX->SetMarkerSize(0.8);
13506   profT->Draw("same");
13507   profT->SetMarkerStyle(3);
13508   profT->SetMarkerColor(4);
13509   profT->SetMarkerSize(0.8);
13510 
13511   //draw the legend
13512   legend->Draw();
13513 
13514   //do second canvas
13515   TLegend *legend2 = new TLegend(0.85, 0.7, 0.9, 0.9);
13516   legend2->SetBorderSize(0);
13517   legend2->SetFillColor(0);
13518   legend2->SetTextSize(0.035);
13519   sGraph="Tracked hits";
13520   legend2->AddEntry(gNum,sGraph.c_str(),"p");
13521   sGraph="Untracked hits";
13522   legend2->AddEntry(gNumX,sGraph.c_str(),"p");
13523   sGraph="All hits";
13524   legend2->AddEntry(gNumT,sGraph.c_str(),"p");
13525 
13526   cResponse->cd(2);
13527   gNumT->Draw("AP");
13528   gNumT->SetTitle("Number hits");
13529   gNumT->GetXaxis()->SetTitle(sXTitle.c_str());
13530   gNumT->GetYaxis()->SetTitle("Num hits");
13531   gNumT->GetXaxis()->CenterTitle();
13532   gNumT->GetYaxis()->CenterTitle();
13533   gNumT->SetMarkerStyle(3);
13534   gNumT->SetMarkerColor(4);
13535   gNumT->SetMarkerSize(0.8);
13536   gNumX->Draw("P");
13537   gNumX->SetMarkerStyle(3);
13538   gNumX->SetMarkerColor(3);
13539   gNumX->SetMarkerSize(0.8);
13540   gNum->Draw("P");
13541   gNum->SetMarkerStyle(3);
13542   gNum->SetMarkerColor(2);
13543   gNum->SetMarkerSize(0.8);
13544 
13545   //draw the legend
13546   legend2->Draw();
13547 }
13548 
13549 //......................................................................
13550 
13551 void CDAnalysis::CleanMuons()
13552 {
13553   MSG("CDAnalysis",Msg::kInfo) 
13554     <<" ** Running CleanMuons method... **"<<endl;
13555 
13556   //open the output file for the histograms
13557   fOutFile=this->OpenFile(fRunNumber,"CleanMuons");
13558 
13559   TH1F *hTime=new TH1F("hTime","hTime",100000,-500-9,500e-9);
13560   hTime->GetXaxis()->SetTitle("Time");
13561   hTime->GetXaxis()->CenterTitle();
13562   hTime->GetYaxis()->SetTitle("");
13563   hTime->GetYaxis()->CenterTitle();
13564   hTime->SetFillColor(0);
13565   //hTime->SetBit(TH1::kCanRebin);
13566 
13567   TH1F *hTime2=new TH1F("hTime2","hTime2",1000000,-1,1);
13568   hTime2->GetXaxis()->SetTitle("Time2");
13569   hTime2->GetXaxis()->CenterTitle();
13570   hTime2->GetYaxis()->SetTitle("");
13571   hTime2->GetYaxis()->CenterTitle();
13572   hTime2->SetFillColor(0);
13573   //hTime2->SetBit(TH1::kCanRebin);
13574 
13575   TProfile2D *hStVsPl1=new TProfile2D("hStVsPl1","StVsPl1",
13576                          67,-2,65,27,-2,25);
13577   hStVsPl1->GetXaxis()->SetTitle("Plane");
13578   hStVsPl1->GetXaxis()->CenterTitle();
13579   hStVsPl1->GetYaxis()->SetTitle("Strip");
13580   hStVsPl1->GetYaxis()->CenterTitle();
13581   hStVsPl1->SetFillColor(0);
13582   hStVsPl1->SetBit(TH1::kCanRebin);
13583 
13584   TProfile2D *hStVsPl2=new TProfile2D("hStVsPl2","StVsPl2",
13585                          67,-2,65,27,-2,25);
13586   hStVsPl2->GetXaxis()->SetTitle("Plane");
13587   hStVsPl2->GetXaxis()->CenterTitle();
13588   hStVsPl2->GetYaxis()->SetTitle("Strip");
13589   hStVsPl2->GetYaxis()->CenterTitle();
13590   hStVsPl2->SetFillColor(0);
13591   hStVsPl2->SetBit(TH1::kCanRebin);
13592 
13593   TH1F *hTofKov1Diff=new TH1F("hTofKov1Diff",
13594                                "hTofKov1Diff",4000,-2,3);
13595   hTofKov1Diff->GetXaxis()->SetTitle("TofTimeStamp");
13596   hTofKov1Diff->GetXaxis()->CenterTitle();
13597   hTofKov1Diff->GetYaxis()->SetTitle("");
13598   hTofKov1Diff->GetYaxis()->CenterTitle();
13599   hTofKov1Diff->SetFillColor(0);
13600   hTofKov1Diff->SetBit(TH1::kCanRebin);
13601 
13602   TH1F *hTofKov3Diff=new TH1F("hTofKov3Diff",
13603                                "hTofKov3Diff",4000,-2,3);
13604   hTofKov3Diff->GetXaxis()->SetTitle("TofTimeStamp");
13605   hTofKov3Diff->GetXaxis()->CenterTitle();
13606   hTofKov3Diff->GetYaxis()->SetTitle("");
13607   hTofKov3Diff->GetYaxis()->CenterTitle();
13608   hTofKov3Diff->SetFillColor(0);
13609   hTofKov3Diff->SetBit(TH1::kCanRebin);
13610 
13611   TH1F *hTofKov1DiffWhole=new TH1F("hTofKov1DiffWhole",
13612                                "hTofKov1DiffWhole",4000,-2,3);
13613   hTofKov1DiffWhole->GetXaxis()->SetTitle("TofTimeStamp");
13614   hTofKov1DiffWhole->GetXaxis()->CenterTitle();
13615   hTofKov1DiffWhole->GetYaxis()->SetTitle("");
13616   hTofKov1DiffWhole->GetYaxis()->CenterTitle();
13617   hTofKov1DiffWhole->SetFillColor(0);
13618   hTofKov1DiffWhole->SetBit(TH1::kCanRebin);
13619 
13620   TH1F *hTofKov3DiffWhole=new TH1F("hTofKov3DiffWhole",
13621                                "hTofKov3DiffWhole",4000,-2,3);
13622   hTofKov3DiffWhole->GetXaxis()->SetTitle("TofTimeStamp");
13623   hTofKov3DiffWhole->GetXaxis()->CenterTitle();
13624   hTofKov3DiffWhole->GetYaxis()->SetTitle("");
13625   hTofKov3DiffWhole->GetYaxis()->CenterTitle();
13626   hTofKov3DiffWhole->SetFillColor(0);
13627   hTofKov3DiffWhole->SetBit(TH1::kCanRebin);
13628 
13629   TH1F *hTofTDC0=new TH1F("hTofTDC0","TofTDC0",400,-2,4000);
13630   hTofTDC0->GetXaxis()->SetTitle("TofTDC0");
13631   hTofTDC0->GetXaxis()->CenterTitle();
13632   hTofTDC0->GetYaxis()->SetTitle("");
13633   hTofTDC0->GetYaxis()->CenterTitle();
13634   hTofTDC0->SetFillColor(0);
13635   hTofTDC0->SetBit(TH1::kCanRebin);
13636 
13637   TH1F *hTofTDC2=new TH1F("hTofTDC2","TofTDC2",400,-2,4000);
13638   hTofTDC2->GetXaxis()->SetTitle("TofTDC2");
13639   hTofTDC2->GetXaxis()->CenterTitle();
13640   hTofTDC2->GetYaxis()->SetTitle("");
13641   hTofTDC2->GetYaxis()->CenterTitle();
13642   hTofTDC2->SetFillColor(0);
13643   hTofTDC2->SetBit(TH1::kCanRebin);
13644 
13645   TH1F *hTofDiff=new TH1F("hTofDiff","TofDiff",1000,0,1000);
13646   hTofDiff->GetXaxis()->SetTitle("TofDiff");
13647   hTofDiff->GetXaxis()->CenterTitle();
13648   hTofDiff->GetYaxis()->SetTitle("");
13649   hTofDiff->GetYaxis()->CenterTitle();
13650   hTofDiff->SetFillColor(0);
13651   //hTofDiff->SetBit(TH1::kCanRebin);
13652 
13653   TH1F *hTofDiffElec=new TH1F("hTofDiffElec","TofDiffElec",1000,0,1000);
13654   hTofDiffElec->GetXaxis()->SetTitle("TofDiff");
13655   hTofDiffElec->GetXaxis()->CenterTitle();
13656   hTofDiffElec->GetYaxis()->SetTitle("");
13657   hTofDiffElec->GetYaxis()->CenterTitle();
13658   hTofDiffElec->SetFillColor(0);
13659   //hTofDiffElec->SetBit(TH1::kCanRebin);
13660 
13661   TH1F *hTofDiffNotElec=new TH1F("hTofDiffNotElec","TofDiffNotElec",
13662                                  1000,0,1000);
13663   hTofDiffNotElec->GetXaxis()->SetTitle("TofDiff");
13664   hTofDiffNotElec->GetXaxis()->CenterTitle();
13665   hTofDiffNotElec->GetYaxis()->SetTitle("");
13666   hTofDiffNotElec->GetYaxis()->CenterTitle();
13667   hTofDiffNotElec->SetFillColor(0);
13668   //hTofDiffNotElec->SetBit(TH1::kCanRebin);
13669 
13670   TH1F *hTofTDC0Whole=new TH1F("hTofTDC0Whole","TofTDC0Whole",
13671                                400,-2,4000);
13672   hTofTDC0Whole->GetXaxis()->SetTitle("TofTDC0");
13673   hTofTDC0Whole->GetXaxis()->CenterTitle();
13674   hTofTDC0Whole->GetYaxis()->SetTitle("");
13675   hTofTDC0Whole->GetYaxis()->CenterTitle();
13676   hTofTDC0Whole->SetFillColor(0);
13677   hTofTDC0Whole->SetBit(TH1::kCanRebin);
13678 
13679   TH1F *hTofTDC2Whole=new TH1F("hTofTDC2Whole","TofTDC2Whole",
13680                                400,-2,4000);
13681   hTofTDC2Whole->GetXaxis()->SetTitle("TofTDC2");
13682   hTofTDC2Whole->GetXaxis()->CenterTitle();
13683   hTofTDC2Whole->GetYaxis()->SetTitle("");
13684   hTofTDC2Whole->GetYaxis()->CenterTitle();
13685   hTofTDC2Whole->SetFillColor(0);
13686   hTofTDC2Whole->SetBit(TH1::kCanRebin);
13687 
13688   TH1F *hTofDiffWhole=new TH1F("hTofDiffWhole","TofDiffWhole",
13689                                1000,-2000,4000);
13690   hTofDiffWhole->GetXaxis()->SetTitle("TofDiff");
13691   hTofDiffWhole->GetXaxis()->CenterTitle();
13692   hTofDiffWhole->GetYaxis()->SetTitle("");
13693   hTofDiffWhole->GetYaxis()->CenterTitle();
13694   hTofDiffWhole->SetFillColor(0);
13695   hTofDiffWhole->SetBit(TH1::kCanRebin);
13696 
13697   TH1F *hKovADC1Whole=new TH1F("hKovADC1Whole","KovADC1Whole",
13698                                400,-5,15000);
13699   hKovADC1Whole->GetXaxis()->SetTitle("KovADC1Whole");
13700   hKovADC1Whole->GetXaxis()->CenterTitle();
13701   hKovADC1Whole->GetYaxis()->SetTitle("");
13702   hKovADC1Whole->GetYaxis()->CenterTitle();
13703   hKovADC1Whole->SetFillColor(0);
13704   hKovADC1Whole->SetBit(TH1::kCanRebin);
13705 
13706   TH1F *hKovADC1=new TH1F("hKovADC1","KovADC1",400,-5,15000);
13707   hKovADC1->GetXaxis()->SetTitle("KovADC1");
13708   hKovADC1->GetXaxis()->CenterTitle();
13709   hKovADC1->GetYaxis()->SetTitle("");
13710   hKovADC1->GetYaxis()->CenterTitle();
13711   hKovADC1->SetFillColor(0);
13712   hKovADC1->SetBit(TH1::kCanRebin);
13713 
13714   TH1F *hKovADC1Cut=new TH1F("hKovADC1Cut","KovADC1Cut",400,-5,15000);
13715   hKovADC1Cut->GetXaxis()->SetTitle("KovADC1Cut");
13716   hKovADC1Cut->GetXaxis()->CenterTitle();
13717   hKovADC1Cut->GetYaxis()->SetTitle("");
13718   hKovADC1Cut->GetYaxis()->CenterTitle();
13719   hKovADC1Cut->SetFillColor(0);
13720   hKovADC1Cut->SetBit(TH1::kCanRebin);
13721 
13722   TH1F *hKovADC3Whole=new TH1F("hKovADC3Whole","KovADC3Whole",
13723                                400,-5,15000);
13724   hKovADC3Whole->GetXaxis()->SetTitle("KovADC3Whole");
13725   hKovADC3Whole->GetXaxis()->CenterTitle();
13726   hKovADC3Whole->GetYaxis()->SetTitle("");
13727   hKovADC3Whole->GetYaxis()->CenterTitle();
13728   hKovADC3Whole->SetFillColor(0);
13729   hKovADC3Whole->SetBit(TH1::kCanRebin);
13730 
13731   TH1F *hKovADC3=new TH1F("hKovADC3","KovADC3",400,-5,15000);
13732   hKovADC3->GetXaxis()->SetTitle("KovADC3");
13733   hKovADC3->GetXaxis()->CenterTitle();
13734   hKovADC3->GetYaxis()->SetTitle("");
13735   hKovADC3->GetYaxis()->CenterTitle();
13736   hKovADC3->SetFillColor(0);
13737   hKovADC3->SetBit(TH1::kCanRebin);
13738 
13739   TH1F *hKovADC3Cut=new TH1F("hKovADC3Cut","KovADC3Cut",400,-5,15000);
13740   hKovADC3Cut->GetXaxis()->SetTitle("KovADC3Cut");
13741   hKovADC3Cut->GetXaxis()->CenterTitle();
13742   hKovADC3Cut->GetYaxis()->SetTitle("");
13743   hKovADC3Cut->GetYaxis()->CenterTitle();
13744   hKovADC3Cut->SetFillColor(0);
13745   hKovADC3Cut->SetBit(TH1::kCanRebin);
13746 
13747   TH1F *hStrip=new TH1F("hStrip","Strips hit",100,-2,30);
13748   hStrip->GetXaxis()->SetTitle("Strip");
13749   hStrip->GetXaxis()->CenterTitle();
13750   hStrip->GetYaxis()->SetTitle("");
13751   hStrip->GetYaxis()->CenterTitle();
13752   hStrip->SetFillColor(0);
13753   hStrip->SetBit(TH1::kCanRebin);
13754 
13755   TH1F *hStripend=new TH1F("hStripend","Stripend hit",120,-2,10);
13756   hStripend->GetXaxis()->SetTitle("Stripend");
13757   hStripend->GetXaxis()->CenterTitle();
13758   hStripend->GetYaxis()->SetTitle("");
13759   hStripend->GetYaxis()->CenterTitle();
13760   hStripend->SetFillColor(0);
13761   hStripend->SetBit(TH1::kCanRebin);
13762 
13763   TH1F *hPlane=new TH1F("hPlane","Planes hit",200,-2,75);
13764   hPlane->GetXaxis()->SetTitle("Plane");
13765   hPlane->GetXaxis()->CenterTitle();
13766   hPlane->GetYaxis()->SetTitle("");
13767   hPlane->GetYaxis()->CenterTitle();
13768   hPlane->SetFillColor(0);
13769   hPlane->SetBit(TH1::kCanRebin);
13770 
13771   TH1F *hNumPlanes=new TH1F("hNumPlanes","NumPlanes hit",200,-2,75);
13772   hNumPlanes->GetXaxis()->SetTitle("NumPlanes");
13773   hNumPlanes->GetXaxis()->CenterTitle();
13774   hNumPlanes->GetYaxis()->SetTitle("");
13775   hNumPlanes->GetYaxis()->CenterTitle();
13776   hNumPlanes->SetFillColor(0);
13777   hNumPlanes->SetBit(TH1::kCanRebin);
13778 
13779   TH1F *hEventLength=new TH1F("hEventLength","EventLength hit",200,-2,75);
13780   hEventLength->GetXaxis()->SetTitle("EventLength");
13781   hEventLength->GetXaxis()->CenterTitle();
13782   hEventLength->GetYaxis()->SetTitle("");
13783   hEventLength->GetYaxis()->CenterTitle();
13784   hEventLength->SetFillColor(0);
13785   hEventLength->SetBit(TH1::kCanRebin);
13786 
13787   TH1F *hChargeSigCor=new TH1F("hChargeSigCor","ChargeSigCor",
13788                                1000,-2,15000);
13789   hChargeSigCor->GetXaxis()->SetTitle("ChargeSigCor");
13790   hChargeSigCor->GetXaxis()->CenterTitle();
13791   hChargeSigCor->GetYaxis()->SetTitle("");
13792   hChargeSigCor->GetYaxis()->CenterTitle();
13793   hChargeSigCor->SetFillColor(0);
13794   hChargeSigCor->SetBit(TH1::kCanRebin);
13795 
13796   TH1F *hChargeSigLin=new TH1F("hChargeSigLin","ChargeSigLin",
13797                                1000,-2,15000);
13798   hChargeSigLin->GetXaxis()->SetTitle("ChargeSigLin");
13799   hChargeSigLin->GetXaxis()->CenterTitle();
13800   hChargeSigLin->GetYaxis()->SetTitle("");
13801   hChargeSigLin->GetYaxis()->CenterTitle();
13802   hChargeSigLin->SetFillColor(0);
13803   hChargeSigLin->SetBit(TH1::kCanRebin);
13804 
13805   TH1F *hChargePe=new TH1F("hChargePe","ChargePe",412,-12,400);
13806   hChargePe->GetXaxis()->SetTitle("ChargePe");
13807   hChargePe->GetXaxis()->CenterTitle();
13808   hChargePe->GetYaxis()->SetTitle("");
13809   hChargePe->GetYaxis()->CenterTitle();
13810   hChargePe->SetFillColor(0);
13811   hChargePe->SetBit(TH1::kCanRebin);
13812 
13813   TH1F *hGain=new TH1F("hGain","Gain",1000,-2,150);
13814   hGain->GetXaxis()->SetTitle("Gain");
13815   hGain->GetXaxis()->CenterTitle();
13816   hGain->GetYaxis()->SetTitle("");
13817   hGain->GetYaxis()->CenterTitle();
13818   hGain->SetFillColor(0);
13819   hGain->SetBit(TH1::kCanRebin);
13820 
13821   TH1F *hAdc=new TH1F("hAdc","Adc",1000,-2,150);
13822   hAdc->GetXaxis()->SetTitle("Adc");
13823   hAdc->GetXaxis()->CenterTitle();
13824   hAdc->GetYaxis()->SetTitle("");
13825   hAdc->GetYaxis()->CenterTitle();
13826   hAdc->SetFillColor(0);
13827   hAdc->SetBit(TH1::kCanRebin);
13828 
13829   TH1F *hdzds=new TH1F("hdzds","dzds",400,-2,2);
13830   hdzds->GetXaxis()->SetTitle("dzds");
13831   hdzds->GetXaxis()->CenterTitle();
13832   hdzds->GetYaxis()->SetTitle("");
13833   hdzds->GetYaxis()->CenterTitle();
13834   hdzds->SetFillColor(0);
13835   hdzds->SetBit(TH1::kCanRebin);
13836 
13837   TH1F *hdsdz=new TH1F("hdsdz","dsdz",400,-2,10);
13838   hdsdz->GetXaxis()->SetTitle("dsdz");
13839   hdsdz->GetXaxis()->CenterTitle();
13840   hdsdz->GetYaxis()->SetTitle("");
13841   hdsdz->GetYaxis()->CenterTitle();
13842   hdsdz->SetFillColor(0);
13843   hdsdz->SetBit(TH1::kCanRebin);
13844 
13845   TH1F *hdydz=new TH1F("hdydz","dydz",400,-5,5);
13846   hdydz->GetXaxis()->SetTitle("dydz");
13847   hdydz->GetXaxis()->CenterTitle();
13848   hdydz->GetYaxis()->SetTitle("");
13849   hdydz->GetYaxis()->CenterTitle();
13850   hdydz->SetFillColor(0);
13851   hdydz->SetBit(TH1::kCanRebin);
13852 
13853   TH1F *hdxdz=new TH1F("hdxdz","dxdz",400,-10,10);
13854   hdxdz->GetXaxis()->SetTitle("dxdz");
13855   hdxdz->GetXaxis()->CenterTitle();
13856   hdxdz->GetYaxis()->SetTitle("");
13857   hdxdz->GetYaxis()->CenterTitle();
13858   hdxdz->SetFillColor(0);
13859   hdxdz->SetBit(TH1::kCanRebin);
13860 
13861   TH1F *hdyds=new TH1F("hdyds","dyds",400,-3,3);
13862   hdyds->GetXaxis()->SetTitle("dyds");
13863   hdyds->GetXaxis()->CenterTitle();
13864   hdyds->GetYaxis()->SetTitle("");
13865   hdyds->GetYaxis()->CenterTitle();
13866   hdyds->SetFillColor(0);
13867   hdyds->SetBit(TH1::kCanRebin);
13868 
13869   TH1F *hdxds=new TH1F("hdxds","dxds",400,-3,3);
13870   hdxds->GetXaxis()->SetTitle("dxds");
13871   hdxds->GetXaxis()->CenterTitle();
13872   hdxds->GetYaxis()->SetTitle("");
13873   hdxds->GetYaxis()->CenterTitle();
13874   hdxds->SetFillColor(0);
13875   hdxds->SetBit(TH1::kCanRebin);
13876 
13877   TH1F *hTransPos=new TH1F("hTransPos","TransPos",1000,-2,35);
13878   hTransPos->GetXaxis()->SetTitle("TransPos");
13879   hTransPos->GetXaxis()->CenterTitle();
13880   hTransPos->GetYaxis()->SetTitle("");
13881   hTransPos->GetYaxis()->CenterTitle();
13882   hTransPos->SetFillColor(0);
13883   hTransPos->SetBit(TH1::kCanRebin);
13884 
13885   TH1F *hYPos=new TH1F("hYPos","YPos",1000,-8,8);
13886   hYPos->GetXaxis()->SetTitle("YPos");
13887   hYPos->GetXaxis()->CenterTitle();
13888   hYPos->GetYaxis()->SetTitle("");
13889   hYPos->GetYaxis()->CenterTitle();
13890   hYPos->SetFillColor(0);
13891   hYPos->SetBit(TH1::kCanRebin);
13892 
13893   TH1F *hEvenResult=new TH1F("hEvenResult","EvenResult",100,-5,5);
13894   hEvenResult->GetXaxis()->SetTitle("EvenResult");
13895   hEvenResult->GetXaxis()->CenterTitle();
13896   hEvenResult->GetYaxis()->SetTitle("");
13897   hEvenResult->GetYaxis()->CenterTitle();
13898   hEvenResult->SetFillColor(0);
13899   hEvenResult->SetBit(TH1::kCanRebin);
13900 
13901   TH1F *hOddResult=new TH1F("hOddResult","OddResult",100,-5,5);
13902   hOddResult->GetXaxis()->SetTitle("OddResult");
13903   hOddResult->GetXaxis()->CenterTitle();
13904   hOddResult->GetYaxis()->SetTitle("");
13905   hOddResult->GetYaxis()->CenterTitle();
13906   hOddResult->SetFillColor(0);
13907   hOddResult->SetBit(TH1::kCanRebin);
13908 
13909   TProfile* pSigCorVsPlane=new TProfile("pSigCorVsPlane",
13910                                         "pSigCorVsPlane",
13911                                         65,-1,64);
13912   TProfile* pSigCorVsOsPlane=new TProfile("pSigCorVsOsPlane",
13913                                          "pSigCorVsOsPlane",
13914                                          70,5,75);
13915 
13916   Bool_t triggerPMT;            //Did the triggerPMT fire?
13917   Bool_t fafErr;                //Faf errors?
13918   Bool_t sparseErr;             //sparse errors?
13919   Int_t trigSource;             //trigger source
13920   Int_t kovADC1;                //Cerenkov ADC value
13921   Int_t kovTimeStamp1;          //Cerenkov TimeStamp
13922   Int_t kovADC2;
13923   Int_t kovTimeStamp2;
13924   Int_t kovADC3;
13925   Int_t kovTimeStamp3;
13926   Int_t snarlTimeFrame;         //Event TimeFrame
13927   ULong_t snarlMinTimeStamp;  //event minimum timetimestamp
13928   ULong_t snarlMaxTimeStamp;  //event maximum timestamp
13929   Int_t tofTDC0;                //TOF tdc0 value
13930   Int_t tofTDC1;                //TOF tdc1 value
13931   Int_t tofTDC2;                //TOF tdc2 value
13932   Int_t tofADC0;                //TOF ADC0 value (not always present) 
13933                                //______Context depends on the run
13934   Int_t tofADC1;                //TOF ADC1 value (not always present) 
13935                                //Used for tof system testing
13936   Int_t tofADC2;                //TOF ADC1 value (not always present) 
13937                                //Used for tof system testing
13938   Int_t tofADCTimeStamp0;       //tof adc timestamps
13939   Int_t tofADCTimeStamp1;
13940   Int_t tofADCTimeStamp2;  
13941   Int_t tofTimeStamp;           //time stamp of TOF readout
13942   Int_t tickSinceLast;          //Ticks since last snarl
13943 
13944   map<Int_t,Float_t> totalSigCor;
13945   map<Int_t,Float_t> totalNum;
13946   map<Int_t,Float_t> totalSigCorOffSet;
13947   map<Int_t,Float_t> totalNumOffSet;
13948   map<Int_t,Float_t> totalSigCor2;
13949   map<Int_t,Float_t> totalNum2;
13950   map<Int_t,Float_t> totalSigCorOffSet2;
13951   map<Int_t,Float_t> totalNumOffSet2;
13952   map<Int_t,Float_t> totalSigCor3;
13953   map<Int_t,Float_t> totalNum3;
13954   map<Int_t,Float_t> totalSigCorOffSet3;
13955   map<Int_t,Float_t> totalNumOffSet3;
13956   vector<TProfile*> pSigCorVsDist;
13957   vector<Int_t> vWindowSize;
13958 
13962   
13963   this->InitialiseLoopVariables();  
13964   
13965   for(Int_t event=0;event<fEvents;event++){
13966     
13967     this->SetLoopVariables(event);
13968 
13969     if (!fPIDInfo){
13970       MAXMSG("CDAnalysis",Msg::kWarning,100)
13971         <<"No PID info: fPIDInfo="<<fPIDInfo<<endl;
13972       continue;
13973     }
13974 
13975     triggerPMT=fPIDInfo->GetTriggerPMT();
13976     fafErr=fPIDInfo->GetFafErr() ;
13977     sparseErr=fPIDInfo->GetSparseErr();
13978     trigSource=fPIDInfo->GetTrigSource();
13979     kovADC1=fPIDInfo->GetKovADC1() ;
13980     kovTimeStamp1=fPIDInfo->GetKovTimeStamp1();
13981     kovADC2=fPIDInfo->GetKovADC2();
13982     kovTimeStamp2=fPIDInfo->GetKovTimeStamp2();
13983     kovADC3=fPIDInfo->GetKovADC3();
13984     kovTimeStamp3=fPIDInfo->GetKovTimeStamp3(); 
13985     snarlTimeFrame=fPIDInfo->GetSnarlTimeFrame();
13986     snarlMinTimeStamp=fPIDInfo->GetSnarlMinTimeStamp();
13987     snarlMaxTimeStamp=fPIDInfo->GetSnarlMaxTimeStamp();
13988     tofTDC0=fPIDInfo->GetTofTDC0();
13989     tofTDC1=fPIDInfo->GetTofTDC1();
13990     tofTDC2=fPIDInfo->GetTofTDC2();
13991     tofADC0=fPIDInfo->GetTofADC0();
13992     tofADC1=fPIDInfo->GetTofADC1();
13993     tofADC2=fPIDInfo->GetTofADC2();
13994     tofADCTimeStamp0=fPIDInfo->GetTofADCTimeStamp0();
13995     tofADCTimeStamp1=fPIDInfo->GetTofADCTimeStamp1();
13996     tofADCTimeStamp2=fPIDInfo->GetTofADCTimeStamp2();
13997     tofTimeStamp=fPIDInfo->GetTofTimeStamp();//don't use
13998     tickSinceLast=fPIDInfo->GetTickSinceLast();
13999     
14000     hKovADC3Whole->Fill(kovADC3);
14001     hKovADC1Whole->Fill(kovADC1);
14002     hTofTDC0Whole->Fill(tofTDC0);
14003     hTofTDC2Whole->Fill(tofTDC2);
14004     hTofDiffWhole->Fill(tofTDC2-tofTDC0);
14005     hTofKov1DiffWhole->Fill(tofADCTimeStamp1-kovTimeStamp1);
14006     hTofKov3DiffWhole->Fill(tofADCTimeStamp1-kovTimeStamp3);
14007 
14008     //if (this->CutOnPidForElec()) continue;
14009 
14010     hEvenResult->Fill(fTrackInfo->GetResult(0));
14011     hOddResult->Fill(fTrackInfo->GetResult(1));
14012 
14013     hTofTDC0->Fill(tofTDC0);
14014     hTofTDC2->Fill(tofTDC2);
14015     hTofDiff->Fill(tofTDC2-tofTDC0);
14016     if (kovADC1>500 && kovADC3>500) hTofDiffElec->Fill(tofTDC2-tofTDC0);
14017     else hTofDiffNotElec->Fill(tofTDC2-tofTDC0);
14018     hTofKov1Diff->Fill(tofADCTimeStamp1-kovTimeStamp1);
14019     hTofKov3Diff->Fill(tofADCTimeStamp1-kovTimeStamp3);
14020 
14021     MSG("CDAnalysis",Msg::kVerbose)//diff is the lemo
14022       <<"ttof="<<tofTimeStamp
14023       <<", tofADCTimeStamp1="<<tofADCTimeStamp1<<endl;
14024 
14025     map<Int_t,Int_t> numPlanesHit;
14026     map<Int_t,Int_t> numPlanesHit1;
14027     map<Int_t,Int_t> numPlanesHit2;
14028     Int_t firstPlane=999999;
14029     Int_t lastPlane=-1;
14030     Int_t lastPlaneOdd=-1;
14031     Int_t lastPlaneEven=-1;
14032     map<Int_t,Float_t> planeSigCor;
14033     map<Int_t,Float_t> planeSigCorX;
14034     map<Int_t,Float_t> planeSigCorT;
14035 
14036     //get tclones arrays for this snarl
14037     TClonesArray &cTrk=*fTrkHitInfo;
14038     Int_t numTrkHits=fTrkHitInfo->GetEntries();
14039     TClonesArray &cUnTrk = *fUnTrkHitInfo;
14040     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
14041     //CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
14042     TClonesArray &cXTalk = *fXTalkHits;
14043     Int_t numXTalkHits=fXTalkHits->GetEntries();
14044           
14045     //look for untracked big events
14046     if (numTrkHits<2 && numXTalkHits+numUnTrkHits>100){
14047       MSG("CDAnalysis",Msg::kDebug)
14048         <<"Event="<<event
14049         <<", Num hits: trk="<<numTrkHits<<", unTrk="<<numUnTrkHits
14050         <<", xtalk="<<numXTalkHits<<endl;
14051     }
14052 
14054     //loop over the untracked hits in the snarl
14056     for (Int_t hit=0;hit<numUnTrkHits;hit++){
14057       CDTrackedHitInfo *hitInfo=(CDTrackedHitInfo*) cUnTrk[hit];
14058 
14059       this->ReadInHitInfo(hitInfo);
14060 
14061       Float_t chargeSigCor=hitInfo->GetCharge
14062         (CDTrackedHitInfo::kSigCorr);
14063       Int_t plane=hitInfo->GetPlane();
14064       Int_t strip=hitInfo->GetStrip();
14065 
14066       //cut out the strips with bad pedestals
14067       if ((plane==21 || plane==41) && strip==19) continue;
14068       //cut out the negative adcs
14069       if (strip==13 && plane==40) continue;
14070 
14071       hTime->Fill(fTime-tofTimeStamp);
14072       hTime2->Fill(fTime-tofTimeStamp);
14073 
14074       //add up the charge of the hits in each plane
14075       planeSigCorX[plane]+=chargeSigCor;
14076       planeSigCorT[plane]+=chargeSigCor;
14077     }
14078 
14080     //loop over xtalk hits in the snarl
14082     for (Int_t hit=0;hit<numXTalkHits;hit++){
14083       CDXTalkHitInfo *hitInfo=(CDXTalkHitInfo*) cXTalk[hit];
14084 
14085       this->ReadInHitInfo(hitInfo);      
14086 
14087       Float_t chargeSigCor=hitInfo->GetCharge
14088         (CDTrackedHitInfo::kSigCorr);
14089       Int_t plane=hitInfo->GetPlane();
14090       Int_t strip=hitInfo->GetStrip();
14091       
14092       //cut out the strips with bad pedestals
14093       if ((plane==21 || plane==41) && strip==19) continue;
14094       //cut out the negative adcs
14095       if (strip==13 && plane==40) continue;
14096 
14097       hTime->Fill(fTime-tofTimeStamp);
14098       hTime2->Fill(fTime-tofTimeStamp);
14099 
14100       //add up the charge of the hits in each plane
14101       planeSigCorX[plane]+=chargeSigCor;
14102       planeSigCorT[plane]+=chargeSigCor;
14103     }
14104 
14106     //loop over the tracked hits
14108     for (Int_t hit=0;hit<numTrkHits;hit++){
14109       CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) cTrk[hit];
14110           
14111       this->ReadInHitInfo(trackedHitInfo);
14112 
14113       Int_t plane=trackedHitInfo->GetPlane();
14114       Int_t strip=trackedHitInfo->GetStrip();
14115       Int_t stripend=trackedHitInfo->GetEnd();
14116 
14117       Float_t chargeSigCor=trackedHitInfo->GetCharge
14118         (CDTrackedHitInfo::kSigCorr);
14119       Float_t chargeSigLin=trackedHitInfo->GetCharge
14120         (CDTrackedHitInfo::kSigLin);
14121       Float_t chargePe=trackedHitInfo->GetCharge
14122         (CDTrackedHitInfo::kPe);
14123       Float_t gain = chargeSigLin/chargePe;
14124       Float_t adc=trackedHitInfo->GetCharge
14125         (CDTrackedHitInfo::kAdc);
14126 
14127       hTime->Fill(fTime-tofTimeStamp);
14128       hTime2->Fill(fTime-tofTimeStamp);
14129 
14130       if (stripend==1) hStVsPl1->Fill(plane,strip,adc);
14131       if (stripend==2) hStVsPl2->Fill(plane,strip,adc);
14132 
14133       //cut out the strips with bad pedestals
14134       if ((plane==21 || plane==41) && strip==19) continue;
14135       //cut out the negative adcs
14136       if (strip==13 && plane==40) continue;
14137 
14138       if (adc<0 && !(strip==13 && plane==40)){
14139         MSG("CDAnalysis",Msg::kInfo)
14140           <<"Event="<<event<<", adc="<<adc<<" ("<<plane<<":"<<strip
14141           <<")"<<endl;
14142       }
14143       else if (adc<0){
14144         MSG("CDAnalysis",Msg::kInfo)
14145           <<"Event="<<event<<", adc="<<adc<<" ("<<plane<<":"<<strip
14146           <<")"<<endl;
14147       }
14148 
14149       hPlane->Fill(plane);
14150       hStrip->Fill(strip);
14151       hStripend->Fill(stripend);
14152 
14153       //count the number of planes hit
14154       numPlanesHit[plane]++;
14155       if (stripend==1) numPlanesHit1[plane]++;
14156       if (stripend==2) numPlanesHit2[plane]++;
14157       if (plane<firstPlane) firstPlane=plane;
14158       if (plane>lastPlane) lastPlane=plane;
14159       if (plane>lastPlaneOdd && plane%2!=0) lastPlaneOdd=plane;
14160       if (plane>lastPlaneEven && plane%2==0) lastPlaneEven=plane;
14161 
14162       //add up the charge of the tracked hits in each plane
14163       planeSigCor[plane]+=chargeSigCor;
14164       planeSigCorT[plane]+=chargeSigCor;
14165 
14166       hChargeSigCor->Fill(chargeSigCor);
14167       hChargeSigLin->Fill(chargeSigLin);
14168       hChargePe->Fill(chargePe);
14169       hGain->Fill(gain);
14170       hAdc->Fill(adc);
14171 
14172       Float_t dzds = trackedHitInfo->GetDzDs();
14173       Float_t dsdz = 1./dzds;
14174       Float_t dydz = trackedHitInfo->GetDyDz();
14175       Float_t dxdz = trackedHitInfo->GetDxDz();
14176       Float_t dyds = trackedHitInfo->GetDyDz()*
14177         trackedHitInfo->GetDzDs();
14178       Float_t dxds = trackedHitInfo->GetDxDz()*
14179         trackedHitInfo->GetDzDs();
14180       Float_t TransPos = trackedHitInfo->GetTransPos();
14181       Float_t YPos = trackedHitInfo->GetYPos();
14182 
14183       hdzds->Fill(dzds);
14184       hdsdz->Fill(dsdz);
14185       hdydz->Fill(dydz);
14186       hdxdz->Fill(dxdz);
14187       hdyds->Fill(dyds);
14188       hdxds->Fill(dxds);
14189       hTransPos->Fill(TransPos);
14190       hYPos->Fill(YPos);
14191     }
14192         
14193     if (firstPlane<0 || firstPlane>59) continue;
14194 
14195     hNumPlanes->Fill(numPlanesHit.size());
14196 
14197     if (firstPlane>=0 && firstPlane<60){
14198       hEventLength->Fill(lastPlane-firstPlane+1);
14199     }
14200 
14201     Float_t pl1Pl2=0;
14202     if (numPlanesHit2.size()>0) pl1Pl2=1.*numPlanesHit1.size()/
14203                                   numPlanesHit2.size();
14204 
14205     if (firstPlane<60 && numPlanesHit.size()>40 && planeSigCor[1]>800 && planeSigCor[2]>800){
14206 
14207       MSG("CDAnalysis",Msg::kVerbose)
14208         <<"Special: ev="<<event
14209         <<", firstPl="<<firstPlane
14210         <<", lastPl="<<lastPlane
14211         <<", nPl="<<numPlanesHit.size()
14212         <<", nPl1="<<numPlanesHit1.size()
14213         <<", nPl2="<<numPlanesHit2.size()
14214         <<", Pl1/Pl2="<<pl1Pl2<<endl;
14215     }
14216 
14217     if (pl1Pl2>2 || pl1Pl2<1./2){
14218       MSG("CDAnalysis",Msg::kVerbose)
14219         <<"1 sided: ev="<<event
14220         <<", firstPl="<<firstPlane
14221         <<", lastPl="<<lastPlane
14222         <<", nPl="<<numPlanesHit.size()
14223         <<", nPl1="<<numPlanesHit1.size()
14224         <<", nPl2="<<numPlanesHit2.size()
14225         <<", Pl1/Pl2="<<pl1Pl2<<endl;
14226     }
14227 
14228     static Int_t counter=0;
14229     counter++;
14230 
14231     if (counter<80){
14232       MSG("CDAnalysis",Msg::kDebug)
14233         <<"Event="<<event
14234         <<", numPlanes="<<numPlanesHit.size()
14235         <<", kov1="<<kovADC1
14236         <<", kov3="<<kovADC3
14237         <<endl;
14238     }
14239 
14240     if (kovADC1>100){
14241       MSG("CDAnalysis",Msg::kDebug)
14242         <<"High Kov Event="<<event
14243         <<", numPlanes="<<numPlanesHit.size()
14244         <<", kov1="<<kovADC1
14245         <<", kov3="<<kovADC3
14246         <<endl;
14247     }
14248 
14249     if (numPlanesHit.size()>40){
14250       hKovADC3->Fill(kovADC3);
14251       hKovADC1->Fill(kovADC1);
14252     }
14253     else{
14254       hKovADC3Cut->Fill(kovADC3);
14255       hKovADC1Cut->Fill(kovADC1);
14256     }
14257 
14258     //make cuts
14259     if (numPlanesHit.size()<40) continue;
14260     if (firstPlane<0 || firstPlane>59) continue;
14261     if (lastPlane>57) continue;//cut out through going muons, no 58,59
14262 
14263     if (numPlanesHit[lastPlane-1]==0){
14264       MSG("CDAnalysis",Msg::kDebug)
14265         <<"Missing lastPlane-1, event="<<event
14266         <<", numPlanes="<<numPlanesHit.size()
14267         <<", kov1="<<kovADC1
14268         <<", kov3="<<kovADC3
14269         <<endl;
14270     }
14271 
14273     //section for response
14275 
14276     const Int_t reNormPlane=70;
14277     Int_t planeOffset=reNormPlane-lastPlane;
14278 
14279     for (map<Int_t,Float_t>::iterator sig=planeSigCor.begin();
14280          sig!=planeSigCor.end();++sig){
14281       totalSigCor[sig->first]+=sig->second;
14282       totalNum[sig->first]++;
14283       pSigCorVsPlane->Fill(sig->first,sig->second);
14284 
14285       totalSigCorOffSet[sig->first+planeOffset]+=sig->second;
14286       totalNumOffSet[sig->first+planeOffset]++;
14287       pSigCorVsOsPlane->Fill(sig->first+planeOffset,sig->second);
14288     }
14289 
14290     for (map<Int_t,Float_t>::iterator sig=planeSigCorX.begin();
14291          sig!=planeSigCorX.end();++sig){
14292       totalSigCor2[sig->first]+=sig->second;
14293       totalNum2[sig->first]++;
14294 
14295       totalSigCorOffSet2[sig->first+planeOffset]+=sig->second;
14296       totalNumOffSet2[sig->first+planeOffset]++;
14297     }
14298 
14299     for (map<Int_t,Float_t>::iterator sig=planeSigCorT.begin();
14300          sig!=planeSigCorT.end();++sig){
14301       totalSigCor3[sig->first]+=sig->second;
14302       totalNum3[sig->first]++;
14303 
14304       totalSigCorOffSet3[sig->first+planeOffset]+=sig->second;
14305       totalNumOffSet3[sig->first+planeOffset]++;
14306     }
14307 
14309     //section for sliding window
14311     Int_t minEventLength=40;
14312     if (lastPlane<minEventLength) continue;
14313 
14314     MSG("CDAnalysis",Msg::kDebug)
14315       <<"Event="<<event
14316       <<", firstPl="<<firstPlane
14317       <<", lastPl="<<lastPlane
14318       <<", lastPlOdd="<<lastPlaneOdd
14319       <<", lastPlEven="<<lastPlaneEven
14320       <<", numPlanes="<<numPlanesHit.size()<<endl;
14321 
14322     //initialise the profile histos
14323     static Bool_t firstTime=true;
14324     if (firstTime){
14325       for (Int_t p=20;p>1;p--){
14326         vWindowSize.push_back(p);
14327       }
14328 
14329       for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
14330            windowSize!=vWindowSize.end();++windowSize){
14331         
14332         string sName=Form("%d",*windowSize);
14333         pSigCorVsDist.push_back
14334           (new TProfile(("pSigCorVsDist"+sName).c_str(),
14335                         ("pSigCorVsDist"+sName).c_str(),100,-2,40));
14336       }
14337     }
14338     firstTime=false;
14339 
14340     vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
14341 
14342     for (vector<Int_t>::iterator windowSize=vWindowSize.begin();
14343          windowSize!=vWindowSize.end();++windowSize){
14344       
14345       for (Int_t p=0;p<minEventLength-*windowSize;p++){
14346         Int_t windowStart=lastPlane-p;
14347 
14348         Float_t avSigCor=0;
14349         Int_t numUsed=0;
14350         
14351         for (Int_t i=0;i<*windowSize;i++){
14352           Int_t plane=windowStart-i;
14353           
14354           MSG("CDAnalysis",Msg::kVerbose)
14355             <<"Event="<<event
14356             <<", winStart="<<windowStart
14357             <<", plane="<<plane<<endl;
14358           
14359           //cut out planes that are greater than the last plane
14360           //in the view - ie the zeros at the end
14361           Bool_t doZeroCorrection=false;
14362           if (doZeroCorrection && 
14363               ((plane%2==0 && plane>lastPlaneEven) || 
14364                (plane%2!=0 && plane>lastPlaneOdd))){
14365             MSG("CDAnalysis",Msg::kVerbose)
14366               <<"Not using: Event="<<event
14367               <<", pl="<<plane
14368               <<", sigCor="<<planeSigCor[plane]
14369               <<", lastPlane="<<lastPlane
14370               <<", lastPlSig="<<planeSigCor[lastPlane]
14371               <<", lastPlOdd="<<lastPlaneOdd
14372               <<", lastPlEven="<<lastPlaneEven
14373               <<endl;
14374           }
14375           else{
14376             avSigCor+=planeSigCor[plane];
14377             numUsed++;
14378             }
14379         }
14380         
14381         //find average
14382         if (numUsed>0) avSigCor/=numUsed;
14383         (*prof)->Fill(p,avSigCor);
14384         
14385         MSG("CDAnalysis",Msg::kDebug)
14386           <<"Event="<<event
14387           <<", winStart="<<windowStart
14388           <<", avSigCor="<<avSigCor<<endl;
14389       }
14390       prof++;
14391     }
14392   }//end of for                                       
14393   
14397 
14398   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
14399   
14400   TCanvas *cProf=new TCanvas("cProf","Prof",0,0,1200,800);
14401   cProf->SetFillColor(0);
14402   string sName="SlidingWindow.ps";
14403   cProf->Print((sName+"[").c_str());
14404   for (vector<TProfile*>::iterator prof=pSigCorVsDist.begin();
14405        prof!=pSigCorVsDist.end();++prof){
14406     cProf->Clear();
14407     (*prof)->Draw();
14408     (*prof)->SetTitle("Average SigCor in Sliding Window");
14409     (*prof)->GetXaxis()->SetTitle("Start of sliding window (planes from end of track)");
14410     (*prof)->GetYaxis()->SetTitle("Average SigCor");
14411     (*prof)->GetXaxis()->CenterTitle();
14412     (*prof)->GetYaxis()->CenterTitle();
14413     cProf->Print(sName.c_str());
14414   }
14415   cProf->Print((sName+"]").c_str());
14416 
14417   this->ScaleMap(totalSigCorOffSet,totalNumOffSet);
14418   TGraph* gPlaneVsAvSigCorOS=this->TGraphMap(totalSigCorOffSet);
14419   TGraph* gPlaneVsNumOS=this->TGraphMap(totalNumOffSet);
14420   this->ScaleMap(totalSigCor,totalNum);
14421   TGraph* gPlaneVsAvSigCor=this->TGraphMap(totalSigCor);
14422   TGraph* gPlaneVsNum=this->TGraphMap(totalNum);
14423 
14424   this->ScaleMap(totalSigCorOffSet2,totalNumOffSet2);
14425   TGraph* gPlaneVsAvSigCorOS2=this->TGraphMap(totalSigCorOffSet2);
14426   TGraph* gPlaneVsNumOS2=this->TGraphMap(totalNumOffSet2);
14427   this->ScaleMap(totalSigCor2,totalNum2);
14428   TGraph* gPlaneVsAvSigCor2=this->TGraphMap(totalSigCor2);
14429   TGraph* gPlaneVsNum2=this->TGraphMap(totalNum2);
14430 
14431   this->ScaleMap(totalSigCorOffSet3,totalNumOffSet3);
14432   TGraph* gPlaneVsAvSigCorOS3=this->TGraphMap(totalSigCorOffSet3);
14433   TGraph* gPlaneVsNumOS3=this->TGraphMap(totalNumOffSet3);
14434   this->ScaleMap(totalSigCor3,totalNum3);
14435   TGraph* gPlaneVsAvSigCor3=this->TGraphMap(totalSigCor3);
14436   TGraph* gPlaneVsNum3=this->TGraphMap(totalNum3);
14437 
14438   TCanvas *cSigCorVsPlane=new TCanvas("cSigCorVsPlane","SigCorVsPlane",
14439                                       0,0,1200,800);
14440   cSigCorVsPlane->SetFillColor(0);
14441   cSigCorVsPlane->Divide(1,2);
14442   cSigCorVsPlane->cd(1);
14443   pSigCorVsPlane->Draw();
14444   pSigCorVsPlane->SetTitle("Energy Deposition (SigCor)");
14445   pSigCorVsPlane->GetXaxis()->SetTitle("Plane");
14446   pSigCorVsPlane->GetYaxis()->SetTitle("Average SigCor");
14447   pSigCorVsPlane->GetXaxis()->CenterTitle();
14448   pSigCorVsPlane->GetYaxis()->CenterTitle();
14449   pSigCorVsPlane->SetMarkerStyle(3);
14450   pSigCorVsPlane->SetMarkerColor(2);
14451   pSigCorVsPlane->SetMarkerSize(0.2);
14452   pSigCorVsPlane->SetLineColor(2);
14453   cSigCorVsPlane->cd(2);
14454   gPlaneVsNum->Draw("AP");
14455   gPlaneVsNum->SetTitle("Number hits");
14456   gPlaneVsNum->GetXaxis()->SetTitle("Normalised plane");
14457   gPlaneVsNum->GetYaxis()->SetTitle("Num hits");
14458   gPlaneVsNum->GetXaxis()->CenterTitle();
14459   gPlaneVsNum->GetYaxis()->CenterTitle();
14460   gPlaneVsNum->SetMarkerStyle(3);
14461   gPlaneVsNum->SetMarkerColor(2);
14462   gPlaneVsNum->SetMarkerSize(0.8);
14463 
14464   TCanvas *cSigCorVsPlane2=new TCanvas("cSigCorVsPlane2",
14465                                        "SigCorVsPlane2",
14466                                        0,0,1200,800);
14467   cSigCorVsPlane2->SetFillColor(0);
14468   cSigCorVsPlane2->Divide(1,2);
14469   cSigCorVsPlane2->cd(1);
14470   pSigCorVsOsPlane->Draw();
14471   pSigCorVsOsPlane->SetTitle("Energy Deposition (SigCor)");
14472   pSigCorVsOsPlane->GetXaxis()->SetTitle("Plane");
14473   pSigCorVsOsPlane->GetYaxis()->SetTitle("Average SigCor");
14474   pSigCorVsOsPlane->GetXaxis()->CenterTitle();
14475   pSigCorVsOsPlane->GetYaxis()->CenterTitle();
14476   pSigCorVsOsPlane->SetMarkerStyle(3);
14477   pSigCorVsOsPlane->SetMarkerColor(3);
14478   pSigCorVsOsPlane->SetMarkerSize(0.4);
14479   pSigCorVsOsPlane->SetLineColor(3);
14480   cSigCorVsPlane2->cd(2);
14481   gPlaneVsNumOS->Draw("AP");
14482   gPlaneVsNumOS->SetTitle("Number hits");
14483   gPlaneVsNumOS->GetXaxis()->SetTitle("Normalised plane");
14484   gPlaneVsNumOS->GetYaxis()->SetTitle("Num hits");
14485   gPlaneVsNumOS->GetXaxis()->CenterTitle();
14486   gPlaneVsNumOS->GetYaxis()->CenterTitle();
14487   gPlaneVsNumOS->SetMarkerStyle(3);
14488   gPlaneVsNumOS->SetMarkerColor(2);
14489   gPlaneVsNumOS->SetMarkerSize(0.8);
14490 
14491   TCanvas *cResponseOS=new TCanvas("cResponseOS","ResponseOS",
14492                                    0,0,1200,800);
14493   cResponseOS->SetFillColor(0);
14494   cResponseOS->Divide(1,2);
14495   cResponseOS->cd(1);
14496   gPlaneVsAvSigCorOS->Draw("AP");
14497   gPlaneVsAvSigCorOS->SetTitle("Muon Energy Deposition");
14498   gPlaneVsAvSigCorOS->GetXaxis()->SetTitle("Normalised plane");
14499   gPlaneVsAvSigCorOS->GetYaxis()->SetTitle("Average SigCor");
14500   gPlaneVsAvSigCorOS->GetXaxis()->CenterTitle();
14501   gPlaneVsAvSigCorOS->GetYaxis()->CenterTitle();
14502   gPlaneVsAvSigCorOS->SetMarkerStyle(3);
14503   gPlaneVsAvSigCorOS->SetMarkerColor(2);
14504   gPlaneVsAvSigCorOS->SetMarkerSize(0.8);
14505   gPlaneVsAvSigCorOS2->Draw("P");
14506   gPlaneVsAvSigCorOS2->SetMarkerStyle(3);
14507   gPlaneVsAvSigCorOS2->SetMarkerColor(3);
14508   gPlaneVsAvSigCorOS2->SetMarkerSize(0.8);
14509   gPlaneVsAvSigCorOS3->Draw("P");
14510   gPlaneVsAvSigCorOS3->SetMarkerStyle(3);
14511   gPlaneVsAvSigCorOS3->SetMarkerColor(4);
14512   gPlaneVsAvSigCorOS3->SetMarkerSize(0.8);
14513   cResponseOS->cd(2);
14514   gPlaneVsNumOS->Draw("AP");
14515   gPlaneVsNumOS->SetTitle("Number hits");
14516   gPlaneVsNumOS->GetXaxis()->SetTitle("Normalised plane");
14517   gPlaneVsNumOS->GetYaxis()->SetTitle("Num hits");
14518   gPlaneVsNumOS->GetXaxis()->CenterTitle();
14519   gPlaneVsNumOS->GetYaxis()->CenterTitle();
14520   gPlaneVsNumOS->SetMarkerStyle(3);
14521   gPlaneVsNumOS->SetMarkerColor(2);
14522   gPlaneVsNumOS->SetMarkerSize(0.8);
14523   gPlaneVsNumOS2->Draw("P");
14524   gPlaneVsNumOS2->SetMarkerStyle(3);
14525   gPlaneVsNumOS2->SetMarkerColor(3);
14526   gPlaneVsNumOS2->SetMarkerSize(0.8);
14527   gPlaneVsNumOS3->Draw("P");
14528   gPlaneVsNumOS3->SetMarkerStyle(3);
14529   gPlaneVsNumOS3->SetMarkerColor(4);
14530   gPlaneVsNumOS3->SetMarkerSize(0.8);
14531 
14532   TCanvas *cResponse=new TCanvas("cResponse","Response",
14533                                    0,0,1200,800);
14534   cResponse->SetFillColor(0);
14535   cResponse->Divide(1,2);
14536   cResponse->cd(1);
14537   gPlaneVsAvSigCor->Draw("AP");
14538   gPlaneVsAvSigCor->SetTitle("Muon Energy Deposition");
14539   gPlaneVsAvSigCor->GetXaxis()->SetTitle("Plane");
14540   gPlaneVsAvSigCor->GetYaxis()->SetTitle("Average SigCor");
14541   gPlaneVsAvSigCor->GetXaxis()->CenterTitle();
14542   gPlaneVsAvSigCor->GetYaxis()->CenterTitle();
14543   gPlaneVsAvSigCor->SetMarkerStyle(3);
14544   gPlaneVsAvSigCor->SetMarkerColor(2);
14545   gPlaneVsAvSigCor->SetMarkerSize(0.8);
14546   gPlaneVsAvSigCor2->Draw("P");
14547   gPlaneVsAvSigCor2->SetMarkerStyle(3);
14548   gPlaneVsAvSigCor2->SetMarkerColor(3);
14549   gPlaneVsAvSigCor2->SetMarkerSize(0.8);
14550   gPlaneVsAvSigCor3->Draw("P");
14551   gPlaneVsAvSigCor3->SetMarkerStyle(3);
14552   gPlaneVsAvSigCor3->SetMarkerColor(4);
14553   gPlaneVsAvSigCor3->SetMarkerSize(0.8);
14554   cResponse->cd(2);
14555   gPlaneVsNum->Draw("AP");
14556   gPlaneVsNum->SetTitle("Number hits");
14557   gPlaneVsNum->GetXaxis()->SetTitle("Plane");
14558   gPlaneVsNum->GetYaxis()->SetTitle("Num hits");
14559   gPlaneVsNum->GetXaxis()->CenterTitle();
14560   gPlaneVsNum->GetYaxis()->CenterTitle();
14561   gPlaneVsNum->SetMarkerStyle(3);
14562   gPlaneVsNum->SetMarkerColor(2);
14563   gPlaneVsNum->SetMarkerSize(0.8);
14564   gPlaneVsNum2->Draw("P");
14565   gPlaneVsNum2->SetMarkerStyle(3);
14566   gPlaneVsNum2->SetMarkerColor(3);
14567   gPlaneVsNum2->SetMarkerSize(0.8);
14568   gPlaneVsNum3->Draw("P");
14569   gPlaneVsNum3->SetMarkerStyle(3);
14570   gPlaneVsNum3->SetMarkerColor(4);
14571   gPlaneVsNum3->SetMarkerSize(0.8);
14572 
14573   /*
14574   TCanvas *cResults=new TCanvas("cResults","Results",0,0,1200,800);
14575   cResults->SetFillColor(0);
14576   cResults->Divide(2,2);
14577   cResults->cd(1);
14578   hEvenResult->Draw();
14579   cResults->cd(2);
14580   hOddResult->Draw();
14581   */
14582 
14583   TCanvas *cKov=new TCanvas("cKov","Kov",0,0,1200,800);
14584   cKov->SetFillColor(0);
14585   cKov->Divide(3,2);
14586   cKov->cd(1);
14587   hKovADC3->Draw();
14588   cKov->cd(2);
14589   hKovADC3Cut->Draw();
14590   cKov->cd(5);
14591   hKovADC1->Draw();
14592   cKov->cd(4);
14593   hKovADC1Cut->Draw();
14594   cKov->cd(3);
14595   hKovADC3Whole->Draw();
14596   cKov->cd(6);
14597   hKovADC1Whole->Draw();
14598 
14599   TCanvas *cTof=new TCanvas("cTof","Tof",0,0,1200,800);
14600   cTof->SetFillColor(0);
14601   hTofDiffNotElec->Draw();
14602   hTofDiffNotElec->SetLineColor(2);
14603   hTofDiffNotElec->SetLineWidth(3);
14604   hTofDiffElec->Draw("sames");
14605   hTofDiffElec->SetLineWidth(3);
14606 
14607   TCanvas *cTofAll=new TCanvas("cTofAll","cTofAll",0,0,1200,800);
14608   cTofAll->SetFillColor(0);
14609   cTofAll->Divide(3,2);
14610   cTofAll->cd(1);
14611   hTofTDC0->Draw();
14612   cTofAll->cd(2);
14613   hTofTDC2->Draw();
14614   cTofAll->cd(3);
14615   hTofDiff->Draw();
14616   cTofAll->cd(4);
14617   hTofTDC0Whole->Draw();
14618   cTofAll->cd(5);
14619   hTofTDC2Whole->Draw();
14620   cTofAll->cd(6);
14621   hTofDiffWhole->Draw();
14622 
14623   TCanvas *cTofKovDiff=new TCanvas("cTofKovDiff","TofKovDiff",
14624                                    0,0,1200,800);
14625   cTofKovDiff->SetFillColor(0);
14626   cTofKovDiff->Divide(2,2);
14627   cTofKovDiff->cd(1);
14628   hTofKov1Diff->Draw();
14629   cTofKovDiff->cd(2);
14630   hTofKov3Diff->Draw();
14631   cTofKovDiff->cd(3);
14632   hTofKov1DiffWhole->Draw();
14633   cTofKovDiff->cd(4);
14634   hTofKov3DiffWhole->Draw();
14635 
14636   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
14637   cGeom->SetFillColor(0);
14638   cGeom->Divide(2,3);
14639   cGeom->cd(1);
14640   hPlane->Draw();
14641   cGeom->cd(2);
14642   hStrip->Draw();
14643   cGeom->cd(3);
14644   hStripend->Draw();
14645   cGeom->cd(4);
14646   hNumPlanes->Draw();
14647   cGeom->cd(5);
14648   hEventLength->Draw();
14649 
14650   /*
14651   TCanvas *cHits=new TCanvas("cHits","Hits",0,0,1200,800);
14652   cHits->SetFillColor(0);
14653   cHits->Divide(2,3);
14654   cHits->cd(1);
14655   hChargeSigCor->Draw();
14656   cHits->cd(2);
14657   hChargeSigLin->Draw();
14658   cHits->cd(3);
14659   hChargePe->Draw();
14660   cHits->cd(4);
14661   hGain->Draw();
14662   cHits->cd(5);
14663   hAdc->Draw();
14664   */
14665 
14666   TCanvas *cStVsPl=new TCanvas("cStVsPl","StVsPl",0,0,1200,800);
14667   cStVsPl->SetFillColor(0);
14668   cStVsPl->Divide(1,2);
14669   cStVsPl->cd(1);
14670   hStVsPl1->Draw("colz");
14671   cStVsPl->cd(2);
14672   hStVsPl2->Draw("colz");
14673 
14674   TCanvas *cTime=new TCanvas("cTime","Time",0,0,1200,800);
14675   cTime->SetFillColor(0);
14676   cTime->Divide(2,3);
14677   cTime->cd(1);
14678   hTime->Draw();
14679   cTime->cd(2);
14680   hTime2->Draw();
14681   cTime->cd(3);
14682 
14683   cTime->cd(4);
14684 
14685   cTime->cd(5);
14686 
14687 
14688   /*
14689  TCanvas *cAngles=new TCanvas("cAngles","Angles",0,0,1200,800);
14690   cAngles->SetFillColor(0);
14691   cAngles->Divide(3,2);
14692   cAngles->cd(1);
14693   hdzds->Draw();
14694   cAngles->cd(2);
14695   hdsdz->Draw();
14696   cAngles->cd(3);
14697   hdydz->Draw();
14698   cAngles->cd(4);
14699   hdxdz->Draw();
14700   cAngles->cd(5);
14701   hdyds->Draw();
14702   cAngles->cd(6);
14703   hdxds->Draw();
14704 
14705   TCanvas *cPos=new TCanvas("cPos","Pos",0,0,1200,800);
14706   cPos->SetFillColor(0);
14707   cPos->Divide(2,1);
14708   cPos->cd(1);
14709   hTransPos->Draw();
14710   cPos->cd(2);
14711   hYPos->Draw();
14712   */
14713 
14714   MSG("CDAnalysis",Msg::kInfo) 
14715     <<" ** Finished CleanMuons method **"<<endl;
14716 }
14717 
14718 //......................................................................
14719 
14720 void CDAnalysis::ValidateTruth()
14721 {
14722   MSG("CDAnalysis",Msg::kInfo) 
14723     <<" ** Running ValidateTruth method... **"<<endl;
14724   
14725   TH1F *hStrip=new TH1F("hStrip","Strips hit",100,-2,30);
14726   hStrip->GetXaxis()->SetTitle("Strip");
14727   hStrip->GetXaxis()->CenterTitle();
14728   hStrip->GetYaxis()->SetTitle("");
14729   hStrip->GetYaxis()->CenterTitle();
14730   hStrip->SetFillColor(0);
14731   hStrip->SetBit(TH1::kCanRebin);
14732 
14733   TH1F *hPlane=new TH1F("hPlane","Planes hit",200,-2,75);
14734   hPlane->GetXaxis()->SetTitle("Plane");
14735   hPlane->GetXaxis()->CenterTitle();
14736   hPlane->GetYaxis()->SetTitle("");
14737   hPlane->GetYaxis()->CenterTitle();
14738   hPlane->SetFillColor(0);
14739   hPlane->SetBit(TH1::kCanRebin);
14740 
14741   TH1F *hNumDigiScintHits=new TH1F("hNumDigiScintHits",
14742                                    "NumDigiScintHits",800,-2,250);
14743   hNumDigiScintHits->GetXaxis()->SetTitle("NumDigiScintHits");
14744   hNumDigiScintHits->GetXaxis()->CenterTitle();
14745   hNumDigiScintHits->GetYaxis()->SetTitle("");
14746   hNumDigiScintHits->GetYaxis()->CenterTitle();
14747   hNumDigiScintHits->SetFillColor(0);
14748   hNumDigiScintHits->SetBit(TH1::kCanRebin);
14749 
14750   TH1F *hPmtTruth1=new TH1F("hPmtTruth1","PmtTruth1",400,-2,125);
14751   hPmtTruth1->GetXaxis()->SetTitle("PmtTruth1");
14752   hPmtTruth1->GetXaxis()->CenterTitle();
14753   hPmtTruth1->GetYaxis()->SetTitle("");
14754   hPmtTruth1->GetYaxis()->CenterTitle();
14755   hPmtTruth1->SetFillColor(0);
14756   hPmtTruth1->SetBit(TH1::kCanRebin);
14757 
14758   TH1F *hPmtTruth2=new TH1F("hPmtTruth2","PmtTruth2",400,-2,125);
14759   hPmtTruth2->GetXaxis()->SetTitle("PmtTruth2");
14760   hPmtTruth2->GetXaxis()->CenterTitle();
14761   hPmtTruth2->GetYaxis()->SetTitle("");
14762   hPmtTruth2->GetYaxis()->CenterTitle();
14763   hPmtTruth2->SetFillColor(0);
14764   hPmtTruth2->SetBit(TH1::kCanRebin);
14765 
14766   TH1F *hVaChip1=new TH1F("hVaChip1","VaChip1",50,-2,5);
14767   hVaChip1->GetXaxis()->SetTitle("VaChip1");
14768   hVaChip1->GetXaxis()->CenterTitle();
14769   hVaChip1->GetYaxis()->SetTitle("");
14770   hVaChip1->GetYaxis()->CenterTitle();
14771   hVaChip1->SetFillColor(0);
14772   hVaChip1->SetBit(TH1::kCanRebin);
14773 
14774   TH1F *hVaChip2=new TH1F("hVaChip2","VaChip2",50,-2,5);
14775   hVaChip2->GetXaxis()->SetTitle("VaChip2");
14776   hVaChip2->GetXaxis()->CenterTitle();
14777   hVaChip2->GetYaxis()->SetTitle("");
14778   hVaChip2->GetYaxis()->CenterTitle();
14779   hVaChip2->SetFillColor(0);
14780   hVaChip2->SetBit(TH1::kCanRebin);
14781 
14782   TH1F *hMainParticle=new TH1F("hMainParticle","MainParticle",200,-20,20);
14783   hMainParticle->GetXaxis()->SetTitle("MainParticle");
14784   hMainParticle->GetXaxis()->CenterTitle();
14785   hMainParticle->GetYaxis()->SetTitle("");
14786   hMainParticle->GetYaxis()->CenterTitle();
14787   hMainParticle->SetFillColor(0);
14788   hMainParticle->SetBit(TH1::kCanRebin);
14789 
14790   TH1F *hTotalEnDep=new TH1F("hTotalEnDep","TotalEnDep",
14791                              500,-5./1000,15./1000);
14792   hTotalEnDep->GetXaxis()->SetTitle("TotalEnDep");
14793   hTotalEnDep->GetXaxis()->CenterTitle();
14794   hTotalEnDep->GetYaxis()->SetTitle("");
14795   hTotalEnDep->GetYaxis()->CenterTitle();
14796   hTotalEnDep->SetFillColor(0);
14797   hTotalEnDep->SetBit(TH1::kCanRebin);
14798 
14799   TH1F *hMainPartEn=new TH1F("hMainPartEn","MainPartEn",500,-0.5,2);
14800   hMainPartEn->GetXaxis()->SetTitle("MainPartEn");
14801   hMainPartEn->GetXaxis()->CenterTitle();
14802   hMainPartEn->GetYaxis()->SetTitle("");
14803   hMainPartEn->GetYaxis()->CenterTitle();
14804   hMainPartEn->SetFillColor(0);
14805   hMainPartEn->SetBit(TH1::kCanRebin);
14806 
14807   TH1F *hMainPathLength=new TH1F("hMainPathLength","MainPathLength",
14808                                  500,-0.01,0.1);
14809   hMainPathLength->GetXaxis()->SetTitle("MainPathLength");
14810   hMainPathLength->GetXaxis()->CenterTitle();
14811   hMainPathLength->GetYaxis()->SetTitle("");
14812   hMainPathLength->GetYaxis()->CenterTitle();
14813   hMainPathLength->SetFillColor(0);
14814   hMainPathLength->SetBit(TH1::kCanRebin);
14815   
14816   TH1F *hEarliestT1=new TH1F("hEarliestT1","EarliestT1",
14817                              2000,-2e-9,20e-9);
14818   hEarliestT1->GetXaxis()->SetTitle("T1");
14819   hEarliestT1->GetXaxis()->CenterTitle();
14820   hEarliestT1->GetYaxis()->SetTitle("");
14821   hEarliestT1->GetYaxis()->CenterTitle();
14822   hEarliestT1->SetFillColor(0);
14823   hEarliestT1->SetBit(TH1::kCanRebin);
14824 
14825   TH1F *hLatestT2=new TH1F("hLatestT2","LatestT2",2000,-2e-9,20e-9);
14826   hLatestT2->GetXaxis()->SetTitle("T1");
14827   hLatestT2->GetXaxis()->CenterTitle();
14828   hLatestT2->GetYaxis()->SetTitle("");
14829   hLatestT2->GetYaxis()->CenterTitle();
14830   hLatestT2->SetFillColor(0);
14831   hLatestT2->SetBit(TH1::kCanRebin);
14832 
14833   TH1F *hMainT1=new TH1F("hMainT1","MainT1",2000,-1e-9,20e-9);
14834   hMainT1->GetXaxis()->SetTitle("T1");
14835   hMainT1->GetXaxis()->CenterTitle();
14836   hMainT1->GetYaxis()->SetTitle("");
14837   hMainT1->GetYaxis()->CenterTitle();
14838   hMainT1->SetFillColor(0);
14839   hMainT1->SetBit(TH1::kCanRebin);
14840 
14841   TH1F *hMainT1b=new TH1F("hMainT1b","MainT1b",2000,-1e-9,20e-9);
14842   hMainT1b->GetXaxis()->SetTitle("T1");
14843   hMainT1b->GetXaxis()->CenterTitle();
14844   hMainT1b->GetYaxis()->SetTitle("");
14845   hMainT1b->GetYaxis()->CenterTitle();
14846   hMainT1b->SetFillColor(0);
14847   //hMainT1b->SetBit(TH1::kCanRebin);
14848 
14849   TH1F *hMainX1=new TH1F("hMainX1","MainX1",2000,-0.6,0.6);
14850   hMainX1->GetXaxis()->SetTitle("X1");
14851   hMainX1->GetXaxis()->CenterTitle();
14852   hMainX1->GetYaxis()->SetTitle("");
14853   hMainX1->GetYaxis()->CenterTitle();
14854   hMainX1->SetFillColor(0);
14855   hMainX1->SetBit(TH1::kCanRebin);
14856 
14857   TH1F *hMainY1=new TH1F("hMainY1","MainY1",8000,-0.025,0.025);
14858   hMainY1->GetXaxis()->SetTitle("Y1");
14859   hMainY1->GetXaxis()->CenterTitle();
14860   hMainY1->GetYaxis()->SetTitle("");
14861   hMainY1->GetYaxis()->CenterTitle();
14862   hMainY1->SetFillColor(0);
14863   hMainY1->SetBit(TH1::kCanRebin);
14864 
14865   TH1F *hMainZ1=new TH1F("hMainZ1","MainZ1",8000,-0.007,0.007);
14866   hMainZ1->GetXaxis()->SetTitle("Z1");
14867   hMainZ1->GetXaxis()->CenterTitle();
14868   hMainZ1->GetYaxis()->SetTitle("");
14869   hMainZ1->GetYaxis()->CenterTitle();
14870   hMainZ1->SetFillColor(0);
14871   hMainZ1->SetBit(TH1::kCanRebin);
14872 
14873   TH1F *hMainT2=new TH1F("hMainT2","MainT2",2000,-1e-9,20e-9);
14874   hMainT2->GetXaxis()->SetTitle("T2");
14875   hMainT2->GetXaxis()->CenterTitle();
14876   hMainT2->GetYaxis()->SetTitle("");
14877   hMainT2->GetYaxis()->CenterTitle();
14878   hMainT2->SetFillColor(0);
14879   hMainT2->SetBit(TH1::kCanRebin);
14880 
14881   TH1F *hMainT2b=new TH1F("hMainT2b","MainT2b",2000,-1e-9,20e-9);
14882   hMainT2b->GetXaxis()->SetTitle("T2");
14883   hMainT2b->GetXaxis()->CenterTitle();
14884   hMainT2b->GetYaxis()->SetTitle("");
14885   hMainT2b->GetYaxis()->CenterTitle();
14886   hMainT2b->SetFillColor(0);
14887   //hMainT2b->SetBit(TH1::kCanRebin);
14888 
14889   TH1F *hMainX2=new TH1F("hMainX2","MainX2",2000,-0.6,0.6);
14890   hMainX2->GetXaxis()->SetTitle("X2");
14891   hMainX2->GetXaxis()->CenterTitle();
14892   hMainX2->GetYaxis()->SetTitle("");
14893   hMainX2->GetYaxis()->CenterTitle();
14894   hMainX2->SetFillColor(0);
14895   hMainX2->SetBit(TH1::kCanRebin);
14896 
14897   TH1F *hMainY2=new TH1F("hMainY2","MainY2",8000,-0.025,0.025);
14898   hMainY2->GetXaxis()->SetTitle("Y2");
14899   hMainY2->GetXaxis()->CenterTitle();
14900   hMainY2->GetYaxis()->SetTitle("");
14901   hMainY2->GetYaxis()->CenterTitle();
14902   hMainY2->SetFillColor(0);
14903   hMainY2->SetBit(TH1::kCanRebin);
14904 
14905   TH1F *hMainZ2=new TH1F("hMainZ2","MainZ2",8000,-0.007,0.007);
14906   hMainZ2->GetXaxis()->SetTitle("Z2");
14907   hMainZ2->GetXaxis()->CenterTitle();
14908   hMainZ2->GetYaxis()->SetTitle("");
14909   hMainZ2->GetYaxis()->CenterTitle();
14910   hMainZ2->SetFillColor(0);
14911   hMainZ2->SetBit(TH1::kCanRebin);
14912 
14913   TH2F *hXvsY=new TH2F("hXvsY","XvsY",200,-0.025,0.025,200,-0.6,0.6);
14914   hXvsY->GetXaxis()->SetTitle("Y");
14915   hXvsY->GetXaxis()->CenterTitle();
14916   hXvsY->GetYaxis()->SetTitle("X");
14917   hXvsY->GetYaxis()->CenterTitle();
14918   hXvsY->SetFillColor(0);
14919   hXvsY->SetBit(TH1::kCanRebin);
14920 
14921   TH2F *hZvsY=new TH2F("hZvsY","ZvsY",200,-0.025,0.025,
14922                        200,-0.007,0.007);
14923   hZvsY->GetXaxis()->SetTitle("Y");
14924   hZvsY->GetXaxis()->CenterTitle();
14925   hZvsY->GetYaxis()->SetTitle("Z");
14926   hZvsY->GetYaxis()->CenterTitle();
14927   hZvsY->SetFillColor(0);
14928   hZvsY->SetBit(TH1::kCanRebin);
14929 
14930   TH1F *hTrueDistToCentre=new TH1F("hTrueDistToCentre",
14931                                    "hTrueDistToCentre",400,-1.5,1.0);
14932   hTrueDistToCentre->GetXaxis()->SetTitle("Distance to plane centre");
14933   hTrueDistToCentre->GetXaxis()->CenterTitle();
14934   hTrueDistToCentre->GetYaxis()->SetTitle("");
14935   hTrueDistToCentre->GetYaxis()->CenterTitle();
14936   hTrueDistToCentre->SetFillColor(0);
14937   hTrueDistToCentre->SetBit(TH1::kCanRebin);
14938 
14942   
14943   this->InitialiseLoopVariables();  
14944   
14945   for(Int_t event=0;event<fEvents;event++){
14946     
14947     this->SetLoopVariables(event);
14948 
14949     if (!fTruthHitInfo) break;
14950 
14951     TClonesArray &cTruth = *fTruthHitInfo;
14952     Int_t numTruthHits=fTruthHitInfo->GetEntries();
14953     
14954     MSG("CDAnalysis",Msg::kDebug)
14955       <<"Event="<<event
14956       <<", truthHits="<<numTruthHits<<endl;
14957 
14959     //loop over the truth hits
14961     for (Int_t hit=0;hit<numTruthHits;hit++){
14962       //cast the tclonesarray up to a truthhitinfo object
14963       CDTruthHitInfo *hitInfo=
14964         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
14965       
14966       const Int_t plane=hitInfo->GetPlane();
14967       const Int_t strip=hitInfo->GetStrip();
14968       const Int_t mainParticle=hitInfo->GetMainParticle();
14969       const Double_t totalEnDep=hitInfo->GetTotalEnDep();
14970       const Double_t mainPartEn=hitInfo->GetMainPartEn();
14971       const Double_t mainPathLength=hitInfo->GetMainPathLength();
14972       const Double_t numDigiScintHits=hitInfo->GetNumDigiScintHits();
14973       const Int_t pmtTruth1=hitInfo->GetPmtTruth1();
14974       const Int_t pmtTruth2=hitInfo->GetPmtTruth2();
14975       const Int_t vaChip1=hitInfo->GetVaChip1();
14976       const Int_t vaChip2=hitInfo->GetVaChip2();
14977       
14978       const Double_t mainT1=hitInfo->GetMainT1();
14979       const Double_t mainX1=hitInfo->GetMainX1();
14980       const Double_t mainY1=hitInfo->GetMainY1();
14981       const Double_t mainZ1=hitInfo->GetMainZ1();
14982       const Double_t mainT2=hitInfo->GetMainT2();
14983       const Double_t mainX2=hitInfo->GetMainX2();
14984       const Double_t mainY2=hitInfo->GetMainY2();
14985       const Double_t mainZ2=hitInfo->GetMainZ2();
14986 
14987       const Double_t earliestT1=hitInfo->GetEarliestT1();
14988       const Double_t latestT2=hitInfo->GetLatestT2();
14989 
14990       //if (plane==0) continue;
14991 
14992       hPlane->Fill(plane);
14993       hStrip->Fill(strip);
14994       hMainParticle->Fill(mainParticle);
14995       hTotalEnDep->Fill(totalEnDep);
14996       hMainPartEn->Fill(mainPartEn);
14997       hMainPathLength->Fill(mainPathLength);
14998       hPmtTruth1->Fill(pmtTruth1);
14999       hPmtTruth2->Fill(pmtTruth2);
15000       hVaChip1->Fill(vaChip1);
15001       hVaChip2->Fill(vaChip2);
15002       hMainT1->Fill(mainT1);
15003       hMainT1b->Fill(mainT1);
15004       hMainX1->Fill(mainX1);
15005       hMainY1->Fill(mainY1);
15006       hMainZ1->Fill(mainZ1);
15007       hMainT2->Fill(mainT2);
15008       hMainT2b->Fill(mainT2);
15009       hMainX2->Fill(mainX2);
15010       hMainY2->Fill(mainY2);
15011       hMainZ2->Fill(mainZ2);
15012       hEarliestT1->Fill(earliestT1);
15013       hLatestT2->Fill(latestT2);
15014       hNumDigiScintHits->Fill(numDigiScintHits);
15015       if (mainY1!=0) hXvsY->Fill(mainY1,mainX1);
15016       if (mainY2!=0) hXvsY->Fill(mainY2,mainX2);
15017       if (mainY1!=0) hZvsY->Fill(mainY1,mainZ1);
15018       if (mainY2!=0) hZvsY->Fill(mainY2,mainZ2);
15019 
15020       Float_t dist=this->TrueDistToPlaneCentre(strip,
15021                                                (mainX1+mainX2)*0.5);
15022       hTrueDistToCentre->Fill(dist);
15023 
15024       //
15025       if (earliestT1>0.15e-4){
15026         MSG("CDAnalysis",Msg::kDebug)
15027           <<"eT1="<<earliestT1<<", lT2="<<latestT2<<endl;
15028       }
15029     }
15030     
15031   }//end of for                                       
15032   
15036 
15037   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
15038 
15039   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
15040   cGeom->SetFillColor(0);
15041   cGeom->Divide(2,3);
15042   cGeom->cd(1);
15043   hPlane->Draw();
15044   cGeom->cd(2);
15045   hStrip->Draw();
15046   cGeom->cd(3);
15047   hVaChip1->Draw();
15048   cGeom->cd(4);
15049   hVaChip2->Draw();
15050   cGeom->cd(5);
15051   hTrueDistToCentre->Draw();
15052 
15053   TCanvas *cMainParticle=new TCanvas("cMainParticle",
15054                                      "MainParticle",0,0,1200,800);
15055   cMainParticle->SetFillColor(0);
15056   cMainParticle->Divide(2,2);
15057   cMainParticle->cd(1);
15058   hMainParticle->Draw();
15059   cMainParticle->cd(2);
15060   hTotalEnDep->Draw();
15061   cMainParticle->cd(3);
15062   hMainPartEn->Draw();
15063   cMainParticle->cd(4);
15064   hMainPathLength->Draw();
15065 
15066   TCanvas *cTruth=new TCanvas("cTruth","Truth",0,0,1200,800);
15067   cTruth->SetFillColor(0);
15068   cTruth->Divide(2,2);
15069   cTruth->cd(1);
15070   hPmtTruth1->Draw();
15071   cTruth->cd(2);
15072   hPmtTruth2->Draw();
15073   cTruth->cd(3);
15074   hNumDigiScintHits->Draw();
15075 
15076   TCanvas *cT=new TCanvas("cT","T",0,0,800,800);
15077   cT->SetFillColor(0);
15078   cT->Divide(2,3);
15079   cT->cd(1);
15080   hMainT1->Draw();
15081   cT->cd(2);
15082   hMainT2->Draw();
15083   cT->cd(3);
15084   hMainT1b->Draw();
15085   cT->cd(4);
15086   hMainT2b->Draw();
15087   cT->cd(5);
15088   hEarliestT1->Draw();
15089   cT->cd(6);
15090   hLatestT2->Draw();
15091 
15092   TCanvas *cXYZ=new TCanvas("cXYZ","XYZ",0,0,800,800);
15093   cXYZ->SetFillColor(0);
15094   cXYZ->Divide(2,3);
15095   cXYZ->cd(1);
15096   hMainX1->Draw();
15097   cXYZ->cd(2);
15098   hMainX2->Draw();
15099   cXYZ->cd(3);
15100   hMainY1->Draw();
15101   cXYZ->cd(4);
15102   hMainY2->Draw();
15103   cXYZ->cd(5);
15104   hMainZ1->Draw();
15105   cXYZ->cd(6);
15106   hMainZ2->Draw();
15107 
15108   TCanvas *cXvsY=new TCanvas("cXvsY","XvsY",0,0,1200,800);
15109   cXvsY->SetFillColor(0);
15110   hXvsY->Draw("colz");
15111 
15112   TCanvas *cZvsY=new TCanvas("cZvsY","ZvsY",0,0,1200,800);
15113   cZvsY->SetFillColor(0);
15114   hZvsY->Draw("colz");
15115 
15116   MSG("CDAnalysis",Msg::kInfo) 
15117     <<" ** Finished ValidateTruth method **"<<endl;
15118 }
15119 
15120 //......................................................................
15121 
15122 void CDAnalysis::ValidateReco()
15123 {
15124   MSG("CDAnalysis",Msg::kInfo) 
15125     <<" ** Running ValidateReco method... **"<<endl;
15126 
15127   TH1F *hTransPos=new TH1F("hTransPos","hTransPos",400,-1,25);
15128   hTransPos->GetXaxis()->SetTitle("transPos");
15129   hTransPos->GetXaxis()->CenterTitle();
15130   hTransPos->GetYaxis()->SetTitle("");
15131   hTransPos->GetYaxis()->CenterTitle();
15132   hTransPos->SetFillColor(0);
15133   hTransPos->SetBit(TH1::kCanRebin);
15134 
15135   TH1F *hTrueX=new TH1F("hTrueX","hTrueX",1000,-1.5,1.5);
15136   hTrueX->GetXaxis()->SetTitle("trueX");
15137   hTrueX->GetXaxis()->CenterTitle();
15138   hTrueX->GetYaxis()->SetTitle("");
15139   hTrueX->GetYaxis()->CenterTitle();
15140   hTrueX->SetFillColor(0);
15141   hTrueX->SetBit(TH1::kCanRebin);
15142 
15143   TH1F *hLargestRadius=new TH1F("hLargestRadius",
15144                                 "hLargestRadius",1000,-1.5,1.5);
15145   hLargestRadius->GetXaxis()->SetTitle("radius");
15146   hLargestRadius->GetXaxis()->CenterTitle();
15147   hLargestRadius->GetYaxis()->SetTitle("");
15148   hLargestRadius->GetYaxis()->CenterTitle();
15149   hLargestRadius->SetFillColor(0);
15150   hLargestRadius->SetBit(TH1::kCanRebin);
15151 
15152   TH1F *hLargestTrueRadius=new TH1F("hLargestTrueRadius",
15153                                 "hLargestTrueRadius",1000,-1.5,1.5);
15154   hLargestTrueRadius->GetXaxis()->SetTitle("radius");
15155   hLargestTrueRadius->GetXaxis()->CenterTitle();
15156   hLargestTrueRadius->GetYaxis()->SetTitle("");
15157   hLargestTrueRadius->GetYaxis()->CenterTitle();
15158   hLargestTrueRadius->SetFillColor(0);
15159   hLargestTrueRadius->SetBit(TH1::kCanRebin);
15160 
15161   TH1F *hDeltaLargestRadius=new TH1F("hDeltaLargestRadius",
15162                                 "hDeltaLargestRadius",1000,-1.5,1.5);
15163   hDeltaLargestRadius->GetXaxis()->SetTitle("radius");
15164   hDeltaLargestRadius->GetXaxis()->CenterTitle();
15165   hDeltaLargestRadius->GetYaxis()->SetTitle("");
15166   hDeltaLargestRadius->GetYaxis()->CenterTitle();
15167   hDeltaLargestRadius->SetFillColor(0);
15168   hDeltaLargestRadius->SetBit(TH1::kCanRebin);
15169 
15170   TH1F *hRecoDistToCentre=new TH1F("hRecoDistToCentre",
15171                                    "hRecoDistToCentre",400,-1.5,1.0);
15172   hRecoDistToCentre->GetXaxis()->SetTitle("Distance to plane centre");
15173   hRecoDistToCentre->GetXaxis()->CenterTitle();
15174   hRecoDistToCentre->GetYaxis()->SetTitle("");
15175   hRecoDistToCentre->GetYaxis()->CenterTitle();
15176   hRecoDistToCentre->SetFillColor(0);
15177   hRecoDistToCentre->SetBit(TH1::kCanRebin);
15178 
15179   TH1F *hTrueDistToCentre=new TH1F("hTrueDistToCentre",
15180                                    "hTrueDistToCentre",400,-1.5,1.0);
15181   hTrueDistToCentre->GetXaxis()->SetTitle("Distance to plane centre");
15182   hTrueDistToCentre->GetXaxis()->CenterTitle();
15183   hTrueDistToCentre->GetYaxis()->SetTitle("");
15184   hTrueDistToCentre->GetYaxis()->CenterTitle();
15185   hTrueDistToCentre->SetFillColor(0);
15186   hTrueDistToCentre->SetBit(TH1::kCanRebin);
15187 
15188   TH1F *hDeltaDistToCentre=new TH1F("hDeltaDistToCentre",
15189                                    "hDeltaDistToCentre (truth-x)",
15190                                     800,-1.5,1.0);
15191   hDeltaDistToCentre->GetXaxis()->SetTitle("Distance to plane centre");
15192   hDeltaDistToCentre->GetXaxis()->CenterTitle();
15193   hDeltaDistToCentre->GetYaxis()->SetTitle("");
15194   hDeltaDistToCentre->GetYaxis()->CenterTitle();
15195   hDeltaDistToCentre->SetFillColor(0);
15196   hDeltaDistToCentre->SetBit(TH1::kCanRebin);
15197 
15198   TH2F* hDistVsTrueDist=new TH2F("hDistVsTrueDist","hDistVsTrueDist",
15199                                  100,0,0.7,100,0,0.7);
15200   hDistVsTrueDist->GetXaxis()->SetTitle("TrueDist");
15201   hDistVsTrueDist->GetXaxis()->CenterTitle();
15202   hDistVsTrueDist->GetYaxis()->SetTitle("RecoDist");
15203   hDistVsTrueDist->GetYaxis()->CenterTitle();
15204   hDistVsTrueDist->SetFillColor(0);
15205   //hDistVsTrueDist->SetMaximum(15000);
15206 
15207   TH2F* hXVsTrueX=new TH2F("hXVsTrueX","hXVsTrueX",
15208                                  100,-0.5,0.5,100,-0.5,0.5);
15209   hXVsTrueX->GetXaxis()->SetTitle("TrueX");
15210   hXVsTrueX->GetXaxis()->CenterTitle();
15211   hXVsTrueX->GetYaxis()->SetTitle("mod(X)");
15212   hXVsTrueX->GetYaxis()->CenterTitle();
15213   hXVsTrueX->SetFillColor(0);
15214   //hXVsTrueX->SetMaximum(15000);
15215 
15216   Int_t totalCounter=0;
15217   Int_t notStraightCounter=0;
15218   Int_t recoFailures=0;
15219   Int_t recoFailures2Sig=0;
15220   Int_t straightTrackCounterTrue=0;
15221   Int_t straightTrackCounter=0;
15222   Int_t straightTrackCounterBoth=0;
15223   
15227   
15228   this->InitialiseLoopVariables();  
15229   
15230   for(Int_t event=0;event<fEvents;event++){
15231     
15232     this->SetLoopVariables(event);
15233 
15234     //cut on straight tracks
15235     //Double_t mainX1Cut=0.4;
15236     //if (this->IsStraightTrack(mainX1Cut)){
15237     //continue;
15238     //}
15239 
15240     totalCounter++;
15241 
15242     Bool_t trueStraight=false;
15243     Bool_t recoStraight=false;
15244     Double_t radiusCut=0.3;
15245 
15246     //section to count tracks
15247     if (this->IsStraightTrack_Radius(radiusCut)){
15248       straightTrackCounterTrue++;
15249       trueStraight=true;
15250     }
15251     if (this->StraightTrack_Radius(radiusCut)){
15252       straightTrackCounter++;
15253       recoStraight=true;
15254     }
15255     if (recoStraight && trueStraight){
15256       straightTrackCounterBoth++;
15257     }
15258 
15259     //now decide if to cut or not
15260     //if (recoStraight) continue;
15261 
15262     notStraightCounter++;
15263     Float_t largestRadius=-1;
15264     Float_t largestTrueRadius=-1;
15265 
15266     //get tclones arrays for this snarl
15267     TClonesArray &cTrk=*fTrkHitInfo;
15268     Int_t numTrkHits=fTrkHitInfo->GetEntries();
15269 
15271     //loop over the tracked hits
15273     for (Int_t hit=0;hit<numTrkHits;hit++){
15274       CDTrackedHitInfo *trackedHitInfo=
15275         dynamic_cast<CDTrackedHitInfo*>(cTrk[hit]);
15276           
15277       this->ReadInHitInfo(trackedHitInfo);
15278 
15279       //calculate the first and last planes
15280       this->CalcFirstLastPlane(fPlane);
15281 
15282       //calc dist to plane centre
15283       Float_t dist=this->CalcDistToPlaneCentre(fStrip,fTransPos);
15284       hRecoDistToCentre->Fill(dist);
15285 
15286       if (dist>largestRadius) largestRadius=dist;
15287 
15288       Float_t trueX=this->TrueXInStripFrame(fPlane,fStrip,event);
15289       MAXMSG("CDAnalysis",Msg::kVerbose,100)
15290         <<"trueX="<<trueX<<endl;
15291 
15292       hTransPos->Fill(fTransPos);
15293       hTrueX->Fill(trueX);
15294 
15295       Float_t distTrue=-1;
15296 
15297       if (trueX!=-1){
15298         distTrue=this->TrueDistToPlaneCentre(fStrip,trueX);
15299         if (distTrue>largestTrueRadius) largestTrueRadius=distTrue;
15300         hTrueDistToCentre->Fill(distTrue);
15301         
15302         if (fTransPos>0 && fTransPos<23){
15303           Float_t transPosFromCentre1=-1;
15304           if (fTransPos<=11) transPosFromCentre1=11-fTransPos;
15305           else if (fTransPos>11) transPosFromCentre1=fTransPos-11;
15306           
15307           //calc real distance
15308           Float_t stripSize=0.041;
15309           Float_t x=transPosFromCentre1*stripSize;
15310           
15311           //sanity check
15312           if (x<0){
15313             MSG("CDAnalysis",Msg::kInfo)
15314               <<"x="<<x<<", transpos="<<fTransPos
15315               <<", transPosFromCentre="<<transPosFromCentre1<<endl;
15316           }
15317 
15318           hXVsTrueX->Fill(trueX,x);
15319         }
15320       }
15321 
15322       if (distTrue!=-1 && dist!=-1){    
15323         Float_t deltaDist=distTrue-dist;
15324         //if (deltaDist<0) deltaDist=deltaDist-2*deltaDist;
15325         hDeltaDistToCentre->Fill(deltaDist);
15326         hDistVsTrueDist->Fill(distTrue,dist);
15327       }
15328     }
15330     //end of loop over the tracked hits
15332 
15333     //count the reco failures where there was a genuine hit
15334     //outside the radius cut but no reco hit within error
15335     if (largestRadius<radiusCut-0.025) recoFailures++; 
15336     if (largestRadius<radiusCut-0.050) recoFailures2Sig++; 
15337     hLargestTrueRadius->Fill(largestTrueRadius);
15338     hLargestRadius->Fill(largestRadius);
15339     if (largestRadius!=-1 && largestTrueRadius!=-1){
15340       hDeltaLargestRadius->Fill(largestTrueRadius-largestRadius);
15341     }
15342     else{
15343       hDeltaLargestRadius->Fill(-1);
15344     }
15345 
15346   }//end of for                                       
15347   
15351 
15352   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
15353 
15354   TCanvas *cPos=new TCanvas("cPos","cPos",0,0,1200,800);
15355   cPos->SetFillColor(0);
15356   cPos->Divide(2,2);
15357   cPos->cd(1);
15358   hRecoDistToCentre->Draw();
15359   cPos->cd(2);
15360   hTrueDistToCentre->Draw();
15361   cPos->cd(3);
15362   hDeltaDistToCentre->Draw();
15363 
15364   TCanvas *cGeom=new TCanvas("cGeom","cGeom",0,0,1200,800);
15365   cGeom->SetFillColor(0);
15366   cGeom->Divide(3,2);
15367   cGeom->cd(1);
15368   hTransPos->Draw();
15369   cGeom->cd(2);
15370   hTrueX->Draw();
15371   cGeom->cd(3);
15372   hLargestRadius->Draw();
15373   cGeom->cd(4);
15374   hLargestTrueRadius->Draw();
15375   cGeom->cd(5);
15376   hDeltaLargestRadius->Draw();
15377   
15378   TCanvas *c2D=new TCanvas("c2D","c2D",0,0,1200,800);
15379   c2D->SetFillColor(0);
15380   c2D->Divide(2,1);
15381   c2D->cd(1);
15382   hDistVsTrueDist->Draw("colz");
15383   c2D->cd(2);
15384   hXVsTrueX->Draw("colz");
15385 
15386   MSG("CDAnalysis",Msg::kInfo) 
15387     <<"Total events="<<totalCounter<<endl
15388     <<"Reco Failures at 1Sig="<<recoFailures<<"/"<<notStraightCounter
15389     <<" ("<<100.*recoFailures/notStraightCounter<<"%)"<<endl
15390     <<"Reco Failures at 2Sig="
15391     <<recoFailures2Sig<<"/"<<notStraightCounter
15392     <<" ("<<100.*recoFailures2Sig/notStraightCounter<<"%)"<<endl
15393     <<"Straight track counter true="<<straightTrackCounterTrue<<endl
15394     <<"Straight track counter reco="<<straightTrackCounter<<endl
15395     <<"Straight track counter both="<<straightTrackCounterBoth<<endl;
15396   
15397   MSG("CDAnalysis",Msg::kInfo) 
15398     <<" ** Finished ValidateReco method **"<<endl;
15399 }
15400 
15401 //......................................................................
15402 
15403 void CDAnalysis::ValidateTrkHits()
15404 {
15405   MSG("CDAnalysis",Msg::kInfo) 
15406     <<" ** Running ValidateTrkHits method... **"<<endl;
15407 
15408   TH1F *hStrip=new TH1F("hStrip","Strips hit",100,-2,30);
15409   hStrip->GetXaxis()->SetTitle("Strip");
15410   hStrip->GetXaxis()->CenterTitle();
15411   hStrip->GetYaxis()->SetTitle("");
15412   hStrip->GetYaxis()->CenterTitle();
15413   hStrip->SetFillColor(0);
15414   hStrip->SetBit(TH1::kCanRebin);
15415 
15416   TH1F *hStripend=new TH1F("hStripend","Stripend hit",120,-2,10);
15417   hStripend->GetXaxis()->SetTitle("Stripend");
15418   hStripend->GetXaxis()->CenterTitle();
15419   hStripend->GetYaxis()->SetTitle("");
15420   hStripend->GetYaxis()->CenterTitle();
15421   hStripend->SetFillColor(0);
15422   hStripend->SetBit(TH1::kCanRebin);
15423 
15424   TH1F *hPlane=new TH1F("hPlane","Planes hit",200,-2,75);
15425   hPlane->GetXaxis()->SetTitle("Plane");
15426   hPlane->GetXaxis()->CenterTitle();
15427   hPlane->GetYaxis()->SetTitle("");
15428   hPlane->GetYaxis()->CenterTitle();
15429   hPlane->SetFillColor(0);
15430   hPlane->SetBit(TH1::kCanRebin);
15431 
15432   TH1F *hChargeSigCor=new TH1F("hChargeSigCor","ChargeSigCor",
15433                                1000,-2,15000);
15434   hChargeSigCor->GetXaxis()->SetTitle("ChargeSigCor");
15435   hChargeSigCor->GetXaxis()->CenterTitle();
15436   hChargeSigCor->GetYaxis()->SetTitle("");
15437   hChargeSigCor->GetYaxis()->CenterTitle();
15438   hChargeSigCor->SetFillColor(0);
15439   hChargeSigCor->SetBit(TH1::kCanRebin);
15440 
15441   TH1F *hChargeSigLin=new TH1F("hChargeSigLin","ChargeSigLin",
15442                                1000,-2,15000);
15443   hChargeSigLin->GetXaxis()->SetTitle("ChargeSigLin");
15444   hChargeSigLin->GetXaxis()->CenterTitle();
15445   hChargeSigLin->GetYaxis()->SetTitle("");
15446   hChargeSigLin->GetYaxis()->CenterTitle();
15447   hChargeSigLin->SetFillColor(0);
15448   hChargeSigLin->SetBit(TH1::kCanRebin);
15449 
15450   TH1F *hChargePe=new TH1F("hChargePe","ChargePe",400,-2,400);
15451   hChargePe->GetXaxis()->SetTitle("ChargePe");
15452   hChargePe->GetXaxis()->CenterTitle();
15453   hChargePe->GetYaxis()->SetTitle("");
15454   hChargePe->GetYaxis()->CenterTitle();
15455   hChargePe->SetFillColor(0);
15456   hChargePe->SetBit(TH1::kCanRebin);
15457 
15458   TH1F *hGain=new TH1F("hGain","Gain",1000,-2,150);
15459   hGain->GetXaxis()->SetTitle("Gain");
15460   hGain->GetXaxis()->CenterTitle();
15461   hGain->GetYaxis()->SetTitle("");
15462   hGain->GetYaxis()->CenterTitle();
15463   hGain->SetFillColor(0);
15464   hGain->SetBit(TH1::kCanRebin);
15465 
15466   TH1F *hdzds=new TH1F("hdzds","dzds",400,-2,2);
15467   hdzds->GetXaxis()->SetTitle("dzds");
15468   hdzds->GetXaxis()->CenterTitle();
15469   hdzds->GetYaxis()->SetTitle("");
15470   hdzds->GetYaxis()->CenterTitle();
15471   hdzds->SetFillColor(0);
15472   hdzds->SetBit(TH1::kCanRebin);
15473 
15474   TH1F *hdsdz=new TH1F("hdsdz","dsdz",400,-2,10);
15475   hdsdz->GetXaxis()->SetTitle("dsdz");
15476   hdsdz->GetXaxis()->CenterTitle();
15477   hdsdz->GetYaxis()->SetTitle("");
15478   hdsdz->GetYaxis()->CenterTitle();
15479   hdsdz->SetFillColor(0);
15480   hdsdz->SetBit(TH1::kCanRebin);
15481 
15482   TH1F *hdydz=new TH1F("hdydz","dydz",400,-5,5);
15483   hdydz->GetXaxis()->SetTitle("dydz");
15484   hdydz->GetXaxis()->CenterTitle();
15485   hdydz->GetYaxis()->SetTitle("");
15486   hdydz->GetYaxis()->CenterTitle();
15487   hdydz->SetFillColor(0);
15488   hdydz->SetBit(TH1::kCanRebin);
15489 
15490   TH1F *hdxdz=new TH1F("hdxdz","dxdz",400,-10,10);
15491   hdxdz->GetXaxis()->SetTitle("dxdz");
15492   hdxdz->GetXaxis()->CenterTitle();
15493   hdxdz->GetYaxis()->SetTitle("");
15494   hdxdz->GetYaxis()->CenterTitle();
15495   hdxdz->SetFillColor(0);
15496   hdxdz->SetBit(TH1::kCanRebin);
15497 
15498   TH1F *hdyds=new TH1F("hdyds","dyds",400,-3,3);
15499   hdyds->GetXaxis()->SetTitle("dyds");
15500   hdyds->GetXaxis()->CenterTitle();
15501   hdyds->GetYaxis()->SetTitle("");
15502   hdyds->GetYaxis()->CenterTitle();
15503   hdyds->SetFillColor(0);
15504   hdyds->SetBit(TH1::kCanRebin);
15505 
15506   TH1F *hdxds=new TH1F("hdxds","dxds",400,-3,3);
15507   hdxds->GetXaxis()->SetTitle("dxds");
15508   hdxds->GetXaxis()->CenterTitle();
15509   hdxds->GetYaxis()->SetTitle("");
15510   hdxds->GetYaxis()->CenterTitle();
15511   hdxds->SetFillColor(0);
15512   hdxds->SetBit(TH1::kCanRebin);
15513 
15514   TH1F *hTransPos=new TH1F("hTransPos","TransPos",1000,-2,35);
15515   hTransPos->GetXaxis()->SetTitle("TransPos");
15516   hTransPos->GetXaxis()->CenterTitle();
15517   hTransPos->GetYaxis()->SetTitle("");
15518   hTransPos->GetYaxis()->CenterTitle();
15519   hTransPos->SetFillColor(0);
15520   hTransPos->SetBit(TH1::kCanRebin);
15521 
15522   TH1F *hYPos=new TH1F("hYPos","YPos",1000,-8,8);
15523   hYPos->GetXaxis()->SetTitle("YPos");
15524   hYPos->GetXaxis()->CenterTitle();
15525   hYPos->GetYaxis()->SetTitle("");
15526   hYPos->GetYaxis()->CenterTitle();
15527   hYPos->SetFillColor(0);
15528   hYPos->SetBit(TH1::kCanRebin);
15529 
15530   TH1F *hEvenResult=new TH1F("hEvenResult","EvenResult",100,-5,5);
15531   hEvenResult->GetXaxis()->SetTitle("EvenResult");
15532   hEvenResult->GetXaxis()->CenterTitle();
15533   hEvenResult->GetYaxis()->SetTitle("");
15534   hEvenResult->GetYaxis()->CenterTitle();
15535   hEvenResult->SetFillColor(0);
15536   hEvenResult->SetBit(TH1::kCanRebin);
15537 
15538   TH1F *hOddResult=new TH1F("hOddResult","OddResult",100,-5,5);
15539   hOddResult->GetXaxis()->SetTitle("OddResult");
15540   hOddResult->GetXaxis()->CenterTitle();
15541   hOddResult->GetYaxis()->SetTitle("");
15542   hOddResult->GetYaxis()->CenterTitle();
15543   hOddResult->SetFillColor(0);
15544   hOddResult->SetBit(TH1::kCanRebin);
15545 
15546   TH1F *hRecoDistToCentre=new TH1F("hRecoDistToCentre",
15547                                    "hRecoDistToCentre",400,-1.5,1.0);
15548   hRecoDistToCentre->GetXaxis()->SetTitle("Distance to plane centre");
15549   hRecoDistToCentre->GetXaxis()->CenterTitle();
15550   hRecoDistToCentre->GetYaxis()->SetTitle("");
15551   hRecoDistToCentre->GetYaxis()->CenterTitle();
15552   hRecoDistToCentre->SetFillColor(0);
15553   hRecoDistToCentre->SetBit(TH1::kCanRebin);
15554 
15555   TH1F *hTrueDistToCentre=new TH1F("hTrueDistToCentre",
15556                                    "hTrueDistToCentre",400,-1.5,1.0);
15557   hTrueDistToCentre->GetXaxis()->SetTitle("Distance to plane centre");
15558   hTrueDistToCentre->GetXaxis()->CenterTitle();
15559   hTrueDistToCentre->GetYaxis()->SetTitle("");
15560   hTrueDistToCentre->GetYaxis()->CenterTitle();
15561   hTrueDistToCentre->SetFillColor(0);
15562   hTrueDistToCentre->SetBit(TH1::kCanRebin);
15563 
15567   
15568   this->InitialiseLoopVariables();  
15569   
15570   for(Int_t event=0;event<fEvents;event++){
15571     
15572     this->SetLoopVariables(event);
15573 
15574     hEvenResult->Fill(fTrackInfo->GetResult(0));
15575     hOddResult->Fill(fTrackInfo->GetResult(1));
15576 
15577     //if(fTrackInfo->GetResult(0)==1 && fTrackInfo->GetResult(1)==1 && 
15578     // fTrkHitInfo){
15579 
15580         TClonesArray &c = *fTrkHitInfo;
15581         Int_t numTrkHits = fTrkHitInfo->GetEntries();
15582         Int_t hit = 0;
15583         
15584         while(hit<numTrkHits) {
15585           CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
15586           
15587           Int_t plane=trackedHitInfo->GetPlane();
15588           Int_t strip=trackedHitInfo->GetStrip();
15589           Int_t stripend=trackedHitInfo->GetEnd();
15590           
15591           hPlane->Fill(plane);
15592           hStrip->Fill(strip);
15593           hStripend->Fill(stripend);
15594 
15595           Float_t chargeSigLin=trackedHitInfo->GetCharge
15596               (CDTrackedHitInfo::kSigLin);
15597           Float_t chargePe=trackedHitInfo->GetCharge
15598               (CDTrackedHitInfo::kPe);
15599           Float_t gain = chargeSigLin/chargePe;
15600 
15601           hChargeSigLin->Fill(chargeSigLin);
15602           hChargePe->Fill(chargePe);
15603           hGain->Fill(gain);
15604 
15605           Float_t dzds = trackedHitInfo->GetDzDs();
15606           Float_t dsdz = 1./dzds;
15607           Float_t dydz = trackedHitInfo->GetDyDz();
15608           Float_t dxdz = trackedHitInfo->GetDxDz();
15609           Float_t dyds = trackedHitInfo->GetDyDz()*
15610               trackedHitInfo->GetDzDs();
15611           Float_t dxds = trackedHitInfo->GetDxDz()*
15612               trackedHitInfo->GetDzDs();
15613           Float_t transPos = trackedHitInfo->GetTransPos();
15614           Float_t YPos = trackedHitInfo->GetYPos();
15615 
15616           //calc dist to plane centre
15617           Float_t dist=this->CalcDistToPlaneCentre(strip,transPos);
15618           hRecoDistToCentre->Fill(dist);
15619 
15620           hdzds->Fill(dzds);
15621           hdsdz->Fill(dsdz);
15622           hdydz->Fill(dydz);
15623           hdxdz->Fill(dxdz);
15624           hdyds->Fill(dyds);
15625           hdxds->Fill(dxds);
15626           hTransPos->Fill(transPos);
15627           hYPos->Fill(YPos);
15628 
15629           hit++;
15630         }
15631         //      }
15632 
15633   }//end of for                                       
15634   
15638 
15639   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
15640 
15641   TCanvas *cResults=new TCanvas("cResults","Results",0,0,1200,800);
15642   cResults->SetFillColor(0);
15643   cResults->Divide(2,2);
15644   cResults->cd(1);
15645   hEvenResult->Draw();
15646   cResults->cd(2);
15647   hOddResult->Draw();
15648 
15649   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
15650   cGeom->SetFillColor(0);
15651   cGeom->Divide(2,2);
15652   cGeom->cd(1);
15653   hPlane->Draw();
15654   cGeom->cd(2);
15655   hStrip->Draw();
15656   cGeom->cd(3);
15657   hStripend->Draw();
15658 
15659   TCanvas *cHits=new TCanvas("cHits","Hits",0,0,1200,800);
15660   cHits->SetFillColor(0);
15661   cHits->Divide(2,2);
15662   cHits->cd(1);
15663   hChargeSigLin->Draw();
15664   cHits->cd(2);
15665   hChargePe->Draw();
15666   cHits->cd(3);
15667   hGain->Draw();
15668 
15669  TCanvas *cAngles=new TCanvas("cAngles","Angles",0,0,1200,800);
15670   cAngles->SetFillColor(0);
15671   cAngles->Divide(3,2);
15672   cAngles->cd(1);
15673   hdzds->Draw();
15674   cAngles->cd(2);
15675   hdsdz->Draw();
15676   cAngles->cd(3);
15677   hdydz->Draw();
15678   cAngles->cd(4);
15679   hdxdz->Draw();
15680   cAngles->cd(5);
15681   hdyds->Draw();
15682   cAngles->cd(6);
15683   hdxds->Draw();
15684 
15685   TCanvas *cPos=new TCanvas("cPos","Pos",0,0,1200,800);
15686   cPos->SetFillColor(0);
15687   cPos->Divide(2,2);
15688   cPos->cd(1);
15689   hTransPos->Draw();
15690   cPos->cd(2);
15691   hYPos->Draw();
15692   cPos->cd(3);
15693   hRecoDistToCentre->Draw();
15694 
15695 
15696   MSG("CDAnalysis",Msg::kInfo) 
15697     <<" ** Finished ValidateTrkHits method **"<<endl;
15698 }
15699 
15700 //......................................................................
15701 
15702 void CDAnalysis::ValidateUnTrkHits()
15703 {
15704   MSG("CDAnalysis",Msg::kInfo) 
15705     <<" ** Running ValidateUnTrkHits method... **"<<endl;
15706 
15707   TH1F *hStrip=new TH1F("hStrip","Strips hit",100,-2,30);
15708   hStrip->GetXaxis()->SetTitle("Strip");
15709   hStrip->GetXaxis()->CenterTitle();
15710   hStrip->GetYaxis()->SetTitle("");
15711   hStrip->GetYaxis()->CenterTitle();
15712   hStrip->SetFillColor(0);
15713   hStrip->SetBit(TH1::kCanRebin);
15714 
15715   TH1F *hStripend=new TH1F("hStripend","Stripend hit",120,-2,10);
15716   hStripend->GetXaxis()->SetTitle("Stripend");
15717   hStripend->GetXaxis()->CenterTitle();
15718   hStripend->GetYaxis()->SetTitle("");
15719   hStripend->GetYaxis()->CenterTitle();
15720   hStripend->SetFillColor(0);
15721   hStripend->SetBit(TH1::kCanRebin);
15722 
15723   TH1F *hPlane=new TH1F("hPlane","Planes hit",200,-2,75);
15724   hPlane->GetXaxis()->SetTitle("Plane");
15725   hPlane->GetXaxis()->CenterTitle();
15726   hPlane->GetYaxis()->SetTitle("");
15727   hPlane->GetYaxis()->CenterTitle();
15728   hPlane->SetFillColor(0);
15729   hPlane->SetBit(TH1::kCanRebin);
15730 
15731   TH1F *hChargeSigLin=new TH1F("hChargeSigLin","ChargeSigLin",
15732                                1000,-2,15000);
15733   hChargeSigLin->GetXaxis()->SetTitle("ChargeSigLin");
15734   hChargeSigLin->GetXaxis()->CenterTitle();
15735   hChargeSigLin->GetYaxis()->SetTitle("");
15736   hChargeSigLin->GetYaxis()->CenterTitle();
15737   hChargeSigLin->SetFillColor(0);
15738   hChargeSigLin->SetBit(TH1::kCanRebin);
15739 
15740   TH1F *hChargePe=new TH1F("hChargePe","ChargePe",400,-2,400);
15741   hChargePe->GetXaxis()->SetTitle("ChargePe");
15742   hChargePe->GetXaxis()->CenterTitle();
15743   hChargePe->GetYaxis()->SetTitle("");
15744   hChargePe->GetYaxis()->CenterTitle();
15745   hChargePe->SetFillColor(0);
15746   hChargePe->SetBit(TH1::kCanRebin);
15747 
15748   TH1F *hGain=new TH1F("hGain","Gain",1000,-2,150);
15749   hGain->GetXaxis()->SetTitle("Gain");
15750   hGain->GetXaxis()->CenterTitle();
15751   hGain->GetYaxis()->SetTitle("");
15752   hGain->GetYaxis()->CenterTitle();
15753   hGain->SetFillColor(0);
15754   hGain->SetBit(TH1::kCanRebin);
15755 
15756   TH1F *hdzds=new TH1F("hdzds","dzds",400,-2,2);
15757   hdzds->GetXaxis()->SetTitle("dzds");
15758   hdzds->GetXaxis()->CenterTitle();
15759   hdzds->GetYaxis()->SetTitle("");
15760   hdzds->GetYaxis()->CenterTitle();
15761   hdzds->SetFillColor(0);
15762   hdzds->SetBit(TH1::kCanRebin);
15763 
15764   TH1F *hdsdz=new TH1F("hdsdz","dsdz",400,-2,10);
15765   hdsdz->GetXaxis()->SetTitle("dsdz");
15766   hdsdz->GetXaxis()->CenterTitle();
15767   hdsdz->GetYaxis()->SetTitle("");
15768   hdsdz->GetYaxis()->CenterTitle();
15769   hdsdz->SetFillColor(0);
15770   hdsdz->SetBit(TH1::kCanRebin);
15771 
15772   TH1F *hdydz=new TH1F("hdydz","dydz",400,-5,5);
15773   hdydz->GetXaxis()->SetTitle("dydz");
15774   hdydz->GetXaxis()->CenterTitle();
15775   hdydz->GetYaxis()->SetTitle("");
15776   hdydz->GetYaxis()->CenterTitle();
15777   hdydz->SetFillColor(0);
15778   hdydz->SetBit(TH1::kCanRebin);
15779 
15780   TH1F *hdxdz=new TH1F("hdxdz","dxdz",400,-10,10);
15781   hdxdz->GetXaxis()->SetTitle("dxdz");
15782   hdxdz->GetXaxis()->CenterTitle();
15783   hdxdz->GetYaxis()->SetTitle("");
15784   hdxdz->GetYaxis()->CenterTitle();
15785   hdxdz->SetFillColor(0);
15786   hdxdz->SetBit(TH1::kCanRebin);
15787 
15788   TH1F *hdyds=new TH1F("hdyds","dyds",400,-3,3);
15789   hdyds->GetXaxis()->SetTitle("dyds");
15790   hdyds->GetXaxis()->CenterTitle();
15791   hdyds->GetYaxis()->SetTitle("");
15792   hdyds->GetYaxis()->CenterTitle();
15793   hdyds->SetFillColor(0);
15794   hdyds->SetBit(TH1::kCanRebin);
15795 
15796   TH1F *hdxds=new TH1F("hdxds","dxds",400,-3,3);
15797   hdxds->GetXaxis()->SetTitle("dxds");
15798   hdxds->GetXaxis()->CenterTitle();
15799   hdxds->GetYaxis()->SetTitle("");
15800   hdxds->GetYaxis()->CenterTitle();
15801   hdxds->SetFillColor(0);
15802   hdxds->SetBit(TH1::kCanRebin);
15803 
15804   TH1F *hTransPos=new TH1F("hTransPos","TransPos",1000,-2,35);
15805   hTransPos->GetXaxis()->SetTitle("TransPos");
15806   hTransPos->GetXaxis()->CenterTitle();
15807   hTransPos->GetYaxis()->SetTitle("");
15808   hTransPos->GetYaxis()->CenterTitle();
15809   hTransPos->SetFillColor(0);
15810   hTransPos->SetBit(TH1::kCanRebin);
15811 
15812   TH1F *hYPos=new TH1F("hYPos","YPos",1000,-8,8);
15813   hYPos->GetXaxis()->SetTitle("YPos");
15814   hYPos->GetXaxis()->CenterTitle();
15815   hYPos->GetYaxis()->SetTitle("");
15816   hYPos->GetYaxis()->CenterTitle();
15817   hYPos->SetFillColor(0);
15818   hYPos->SetBit(TH1::kCanRebin);
15819 
15820   TH1F *hEvenResult=new TH1F("hEvenResult","EvenResult",100,-5,5);
15821   hEvenResult->GetXaxis()->SetTitle("EvenResult");
15822   hEvenResult->GetXaxis()->CenterTitle();
15823   hEvenResult->GetYaxis()->SetTitle("");
15824   hEvenResult->GetYaxis()->CenterTitle();
15825   hEvenResult->SetFillColor(0);
15826   hEvenResult->SetBit(TH1::kCanRebin);
15827 
15828   TH1F *hOddResult=new TH1F("hOddResult","OddResult",100,-5,5);
15829   hOddResult->GetXaxis()->SetTitle("OddResult");
15830   hOddResult->GetXaxis()->CenterTitle();
15831   hOddResult->GetYaxis()->SetTitle("");
15832   hOddResult->GetYaxis()->CenterTitle();
15833   hOddResult->SetFillColor(0);
15834   hOddResult->SetBit(TH1::kCanRebin);
15835 
15836   MSG("CDAnalysis",Msg::kInfo)<<"Starting main loop..."<<endl;
15837 
15841   
15842   this->InitialiseLoopVariables();  
15843   
15844   for(Int_t event=0;event<fEvents;event++){
15845     
15846     this->SetLoopVariables(event);
15847 
15848     hEvenResult->Fill(fTrackInfo->GetResult(0));
15849     hOddResult->Fill(fTrackInfo->GetResult(1));
15850 
15851     //if(fTrackInfo->GetResult(0)==1 && fTrackInfo->GetResult(1)==1 && 
15852     // fTrkHitInfo){
15853 
15854     //just need to change this bit to do tracked or untracked
15855     TClonesArray &c = *fUnTrkHitInfo;
15856     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
15857     Int_t hit = 0;
15858     
15859     while(hit<numUnTrkHits) {
15860       CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
15861 
15862       Int_t plane=trackedHitInfo->GetPlane();
15863       Int_t strip=trackedHitInfo->GetStrip();
15864       Int_t stripend=trackedHitInfo->GetEnd();
15865       
15866       hPlane->Fill(plane);
15867       hStrip->Fill(strip);
15868       hStripend->Fill(stripend);
15869       
15870       Float_t chargeSigLin=trackedHitInfo->GetCharge
15871         (CDTrackedHitInfo::kSigLin);
15872       Float_t chargePe=trackedHitInfo->GetCharge
15873         (CDTrackedHitInfo::kPe);
15874       Float_t gain =chargeSigLin/chargePe;
15875       
15876       hChargeSigLin->Fill(chargeSigLin);
15877       hChargePe->Fill(chargePe);
15878       hGain->Fill(gain);
15879       
15880       Float_t dzds = trackedHitInfo->GetDzDs();
15881       Float_t dsdz=-2;
15882       if (dzds!=0){
15883         dsdz = 1./dzds;
15884       }
15885       Float_t dydz = trackedHitInfo->GetDyDz();
15886       Float_t dxdz = trackedHitInfo->GetDxDz();
15887       Float_t dyds = trackedHitInfo->GetDyDz()*
15888         trackedHitInfo->GetDzDs();
15889       Float_t dxds = trackedHitInfo->GetDxDz()*
15890         trackedHitInfo->GetDzDs();
15891       Float_t TransPos = trackedHitInfo->GetTransPos();
15892       Float_t YPos = trackedHitInfo->GetYPos();
15893       
15894       hdzds->Fill(dzds);
15895       hdsdz->Fill(dsdz);
15896       hdydz->Fill(dydz);
15897       hdxdz->Fill(dxdz);
15898       hdyds->Fill(dyds);
15899       hdxds->Fill(dxds);
15900       hTransPos->Fill(TransPos);
15901       hYPos->Fill(YPos);
15902       
15903       hit++;
15904     }
15905   }//end of for                                       
15906   
15910 
15911   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
15912 
15913   TCanvas *cResults=new TCanvas("cResults","Results",0,0,1200,800);
15914   cResults->SetFillColor(0);
15915   cResults->Divide(2,2);
15916   cResults->cd(1);
15917   hEvenResult->Draw();
15918   cResults->cd(2);
15919   hOddResult->Draw();
15920 
15921   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
15922   cGeom->SetFillColor(0);
15923   cGeom->Divide(2,2);
15924   cGeom->cd(1);
15925   hPlane->Draw();
15926   cGeom->cd(2);
15927   hStrip->Draw();
15928   cGeom->cd(3);
15929   hStripend->Draw();
15930 
15931   TCanvas *cHits=new TCanvas("cHits","Hits",0,0,1200,800);
15932   cHits->SetFillColor(0);
15933   cHits->Divide(2,2);
15934   cHits->cd(1);
15935   hChargeSigLin->Draw();
15936   cHits->cd(2);
15937   hChargePe->Draw();
15938   cHits->cd(3);
15939   hGain->Draw();
15940 
15941  TCanvas *cAngles=new TCanvas("cAngles","Angles",0,0,1200,800);
15942   cAngles->SetFillColor(0);
15943   cAngles->Divide(3,2);
15944   cAngles->cd(1);
15945   hdzds->Draw();
15946   cAngles->cd(2);
15947   hdsdz->Draw();
15948   cAngles->cd(3);
15949   hdydz->Draw();
15950   cAngles->cd(4);
15951   hdxdz->Draw();
15952   cAngles->cd(5);
15953   hdyds->Draw();
15954   cAngles->cd(6);
15955   hdxds->Draw();
15956 
15957   TCanvas *cPos=new TCanvas("cPos","Pos",0,0,1200,800);
15958   cPos->SetFillColor(0);
15959   cPos->Divide(2,1);
15960   cPos->cd(1);
15961   hTransPos->Draw();
15962   cPos->cd(2);
15963   hYPos->Draw();
15964 
15965   MSG("CDAnalysis",Msg::kInfo) 
15966     <<" ** Finished ValidateUnTrkHits method **"<<endl;
15967 }
15968 
15969 //......................................................................
15970 
15971 void CDAnalysis::ValidateXTalkHits()
15972 {
15973   MSG("CDAnalysis",Msg::kInfo) 
15974     <<" ** Running ValidateXTalkHits method... **"<<endl;
15975 
15976   TH1F *hStrip=new TH1F("hStrip","Strips hit",100,-2,30);
15977   hStrip->GetXaxis()->SetTitle("Strip");
15978   hStrip->GetXaxis()->CenterTitle();
15979   hStrip->GetYaxis()->SetTitle("");
15980   hStrip->GetYaxis()->CenterTitle();
15981   hStrip->SetFillColor(0);
15982   hStrip->SetBit(TH1::kCanRebin);
15983 
15984   TH1F *hStripend=new TH1F("hStripend","Stripend hit",120,-2,10);
15985   hStripend->GetXaxis()->SetTitle("Stripend");
15986   hStripend->GetXaxis()->CenterTitle();
15987   hStripend->GetYaxis()->SetTitle("");
15988   hStripend->GetYaxis()->CenterTitle();
15989   hStripend->SetFillColor(0);
15990   hStripend->SetBit(TH1::kCanRebin);
15991 
15992   TH1F *hPlane=new TH1F("hPlane","Planes hit",200,-2,75);
15993   hPlane->GetXaxis()->SetTitle("Plane");
15994   hPlane->GetXaxis()->CenterTitle();
15995   hPlane->GetYaxis()->SetTitle("");
15996   hPlane->GetYaxis()->CenterTitle();
15997   hPlane->SetFillColor(0);
15998   hPlane->SetBit(TH1::kCanRebin);
15999 
16000   TH1F *hChargeSigLin=new TH1F("hChargeSigLin","ChargeSigLin",
16001                                1000,-2,15000);
16002   hChargeSigLin->GetXaxis()->SetTitle("ChargeSigLin");
16003   hChargeSigLin->GetXaxis()->CenterTitle();
16004   hChargeSigLin->GetYaxis()->SetTitle("");
16005   hChargeSigLin->GetYaxis()->CenterTitle();
16006   hChargeSigLin->SetFillColor(0);
16007   hChargeSigLin->SetBit(TH1::kCanRebin);
16008 
16009   TH1F *hChargePe=new TH1F("hChargePe","ChargePe",400,-2,400);
16010   hChargePe->GetXaxis()->SetTitle("ChargePe");
16011   hChargePe->GetXaxis()->CenterTitle();
16012   hChargePe->GetYaxis()->SetTitle("");
16013   hChargePe->GetYaxis()->CenterTitle();
16014   hChargePe->SetFillColor(0);
16015   hChargePe->SetBit(TH1::kCanRebin);
16016 
16017   TH1F *hGain=new TH1F("hGain","Gain",1000,-2,150);
16018   hGain->GetXaxis()->SetTitle("Gain");
16019   hGain->GetXaxis()->CenterTitle();
16020   hGain->GetYaxis()->SetTitle("");
16021   hGain->GetYaxis()->CenterTitle();
16022   hGain->SetFillColor(0);
16023   hGain->SetBit(TH1::kCanRebin);
16024 
16025   TH1F *hNumXTalkHits=new TH1F("hNumXTalkHits","NumXTalkHits",400,-2,2);
16026   hNumXTalkHits->GetXaxis()->SetTitle("NumXTalkHits");
16027   hNumXTalkHits->GetXaxis()->CenterTitle();
16028   hNumXTalkHits->GetYaxis()->SetTitle("");
16029   hNumXTalkHits->GetYaxis()->CenterTitle();
16030   hNumXTalkHits->SetFillColor(0);
16031   hNumXTalkHits->SetBit(TH1::kCanRebin);
16032 
16033   TH1F *hPixel=new TH1F("hPixel","Pixel",100,-2,20);
16034   hPixel->GetXaxis()->SetTitle("Pixel");
16035   hPixel->GetXaxis()->CenterTitle();
16036   hPixel->GetYaxis()->SetTitle("");
16037   hPixel->GetYaxis()->CenterTitle();
16038   hPixel->SetFillColor(0);
16039   hPixel->SetBit(TH1::kCanRebin);
16040 
16041   TH1F *hSourceEnd=new TH1F("hSourceEnd","SourceEnd",50,-2,5);
16042   hSourceEnd->GetXaxis()->SetTitle("SourceEnd");
16043   hSourceEnd->GetXaxis()->CenterTitle();
16044   hSourceEnd->GetYaxis()->SetTitle("");
16045   hSourceEnd->GetYaxis()->CenterTitle();
16046   hSourceEnd->SetFillColor(0);
16047   hSourceEnd->SetBit(TH1::kCanRebin);
16048 
16049   TH1F *hSourcePlane=new TH1F("hSourcePlane","SourcePlane",200,-2,75);
16050   hSourcePlane->GetXaxis()->SetTitle("SourcePlane");
16051   hSourcePlane->GetXaxis()->CenterTitle();
16052   hSourcePlane->GetYaxis()->SetTitle("");
16053   hSourcePlane->GetYaxis()->CenterTitle();
16054   hSourcePlane->SetFillColor(0);
16055   hSourcePlane->SetBit(TH1::kCanRebin);
16056 
16057   TH1F *hSourceStrip=new TH1F("hSourceStrip","SourceStrip",100,-2,30);
16058   hSourceStrip->GetXaxis()->SetTitle("SourceStrip");
16059   hSourceStrip->GetXaxis()->CenterTitle();
16060   //hSourceStrip->GetYaxis()->SetTitle("");
16061   hSourceStrip->GetYaxis()->CenterTitle();
16062   hSourceStrip->SetFillColor(0);
16063   hSourceStrip->SetBit(TH1::kCanRebin);
16064 
16065   TH1F *hSourcePixel=new TH1F("hSourcePixel","SourcePixel",100,-2,20);
16066   hSourcePixel->GetXaxis()->SetTitle("SourcePixel");
16067   hSourcePixel->GetXaxis()->CenterTitle();
16068   hSourcePixel->GetYaxis()->SetTitle("");
16069   hSourcePixel->GetYaxis()->CenterTitle();
16070   hSourcePixel->SetFillColor(0);
16071   hSourcePixel->SetBit(TH1::kCanRebin);
16072 
16073   TH1F *hSourceSpot=new TH1F("hSourceSpot","SourceSpot",400,-2,10);
16074   hSourceSpot->GetXaxis()->SetTitle("SourceSpot");
16075   hSourceSpot->GetXaxis()->CenterTitle();
16076   hSourceSpot->GetYaxis()->SetTitle("");
16077   hSourceSpot->GetYaxis()->CenterTitle();
16078   hSourceSpot->SetFillColor(0);
16079   hSourceSpot->SetBit(TH1::kCanRebin);
16080 
16081   TH1F *hSourceCharge=new TH1F("hSourceCharge","SourceCharge",
16082                                10000,-2,10000);
16083   hSourceCharge->GetXaxis()->SetTitle("SourceCharge");
16084   hSourceCharge->GetXaxis()->CenterTitle();
16085   hSourceCharge->GetYaxis()->SetTitle("");
16086   hSourceCharge->GetYaxis()->CenterTitle();
16087   hSourceCharge->SetFillColor(0);
16088   hSourceCharge->SetBit(TH1::kCanRebin);
16089 
16090   TH1F *hTime=new TH1F("hTime","Time",10000,-2,2);
16091   hTime->GetXaxis()->SetTitle("Time");
16092   hTime->GetXaxis()->CenterTitle();
16093   hTime->GetYaxis()->SetTitle("");
16094   hTime->GetYaxis()->CenterTitle();
16095   hTime->SetFillColor(0);
16096   hTime->SetBit(TH1::kCanRebin);
16097 
16098   TH1F *hEvenResult=new TH1F("hEvenResult","EvenResult",100,-5,5);
16099   hEvenResult->GetXaxis()->SetTitle("EvenResult");
16100   hEvenResult->GetXaxis()->CenterTitle();
16101   hEvenResult->GetYaxis()->SetTitle("");
16102   hEvenResult->GetYaxis()->CenterTitle();
16103   hEvenResult->SetFillColor(0);
16104   hEvenResult->SetBit(TH1::kCanRebin);
16105 
16106   TH1F *hOddResult=new TH1F("hOddResult","OddResult",100,-5,5);
16107   hOddResult->GetXaxis()->SetTitle("OddResult");
16108   hOddResult->GetXaxis()->CenterTitle();
16109   hOddResult->GetYaxis()->SetTitle("");
16110   hOddResult->GetYaxis()->CenterTitle();
16111   hOddResult->SetFillColor(0);
16112   hOddResult->SetBit(TH1::kCanRebin);
16113 
16114   TH2F *hPmtFace=new TH2F("hPmtFace","PmtFace",6,0,6,6,0,6);
16115   hPmtFace->GetXaxis()->SetTitle("");
16116   hPmtFace->GetXaxis()->CenterTitle();
16117   hPmtFace->GetYaxis()->SetTitle("");
16118   hPmtFace->GetYaxis()->CenterTitle();
16119   hPmtFace->SetFillColor(0);
16120   hPmtFace->SetBit(TH1::kCanRebin);
16121 
16122   TH2F *hSpotVsPix=new TH2F("hSpotVsPix","SpotVsPix",17,0,17,10,0,10);
16123   hSpotVsPix->GetXaxis()->SetTitle("Pixel");
16124   hSpotVsPix->GetXaxis()->CenterTitle();
16125   hSpotVsPix->GetYaxis()->SetTitle("Spot");
16126   hSpotVsPix->GetYaxis()->CenterTitle();
16127   hSpotVsPix->SetFillColor(0);
16128   hSpotVsPix->SetBit(TH1::kCanRebin);
16129 
16133   
16134   this->InitialiseLoopVariables();  
16135   
16136   for(Int_t event=0;event<fEvents;event++){
16137     
16138     this->SetLoopVariables(event);
16139 
16140     hEvenResult->Fill(fTrackInfo->GetResult(0));
16141     hOddResult->Fill(fTrackInfo->GetResult(1));
16142 
16143     //if(fTrackInfo->GetResult(0)==1 && fTrackInfo->GetResult(1)==1 && 
16144     // fTrkHitInfo){
16145 
16146         TClonesArray &c = *fXTalkHits;
16147         Int_t numHits=fXTalkHits->GetEntries();
16148         Int_t hit = 0;
16149         
16150         while(hit<numHits) {
16151           CDXTalkHitInfo *xTalkHits=(CDXTalkHitInfo*) c[hit];
16152           
16153           Int_t plane=xTalkHits->GetPlane();
16154           Int_t strip=xTalkHits->GetStrip();
16155           Int_t stripend=xTalkHits->GetEnd();
16156           Int_t pixel=xTalkHits->GetPixel();
16157           
16158           hPlane->Fill(plane);
16159           hStrip->Fill(strip);
16160           hStripend->Fill(stripend);
16161           hPixel->Fill(pixel);
16162 
16163           Float_t chargeSigLin=xTalkHits->GetCharge
16164             (CalDigitType::kSigLin);
16165           Float_t chargePe=xTalkHits->GetCharge(CalDigitType::kPE);
16166           Float_t gain=chargeSigLin/chargePe;
16167           Float_t sourceCharge=xTalkHits->GetSourceCharge();
16168 
16169           hChargeSigLin->Fill(chargeSigLin);
16170           hChargePe->Fill(chargePe);
16171           hGain->Fill(gain);
16172           hSourceCharge->Fill(sourceCharge);
16173 
16174           Int_t numXTalkHits=xTalkHits->GetNumxhits();
16175           Int_t sourceEnd=xTalkHits->GetSourceEnd();
16176           Int_t sourcePlane=xTalkHits->GetSourcePlane();
16177           Int_t sourceStrip=xTalkHits->GetSourceStrip();
16178           Int_t sourcePixel=xTalkHits->GetSourcePixel();
16179           Int_t sourceSpot=xTalkHits->GetSourceSpot();
16180           Double_t time=xTalkHits->GetTime();
16181 
16182           hNumXTalkHits->Fill(numXTalkHits);
16183           hSourceEnd->Fill(sourceEnd);
16184           hSourcePlane->Fill(sourcePlane);
16185           hSourceStrip->Fill(sourceStrip);
16186           hSourcePixel->Fill(sourcePixel);
16187           hSourceSpot->Fill(sourceSpot);
16188           hTime->Fill(time);
16189 
16190           Int_t x=((sourcePixel-1)%4)+1;
16191           Int_t y=((sourcePixel-1)/4)+1;
16192           hPmtFace->Fill(x,y);
16193 
16194           hSpotVsPix->Fill(sourcePixel,sourceSpot);
16195 
16196           hit++;
16197         }
16198   }//end of for                                       
16199   
16203 
16204   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
16205 
16206   TCanvas *cResults=new TCanvas("cResults","Results",0,0,1200,800);
16207   cResults->SetFillColor(0);
16208   cResults->Divide(2,2);
16209   cResults->cd(1);
16210   hEvenResult->Draw();
16211   cResults->cd(2);
16212   hOddResult->Draw();
16213 
16214   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
16215   cGeom->SetFillColor(0);
16216   cGeom->Divide(2,2);
16217   cGeom->cd(1);
16218   hPlane->Draw();
16219   cGeom->cd(2);
16220   hStrip->Draw();
16221   cGeom->cd(3);
16222   hStripend->Draw();
16223   cGeom->cd(4);
16224   hPixel->Draw();
16225 
16226   TCanvas *cHits=new TCanvas("cHits","Hits",0,0,1200,800);
16227   cHits->SetFillColor(0);
16228   cHits->Divide(2,2);
16229   cHits->cd(1);
16230   hChargeSigLin->Draw();
16231   cHits->cd(2);
16232   hChargePe->Draw();
16233   cHits->cd(3);
16234   hGain->Draw();
16235   cHits->cd(4);
16236   hSourceCharge->Draw();
16237 
16238   TCanvas *cSource=new TCanvas("cSource","Source",0,0,1200,800);
16239   cSource->SetFillColor(0);
16240   cSource->Divide(3,2);
16241   cSource->cd(1);
16242   hNumXTalkHits->Draw();
16243   cSource->cd(2);
16244   hSourceEnd->Draw();
16245   cSource->cd(3);
16246   hSourcePlane->Draw();
16247   cSource->cd(4);
16248   hSourceStrip->Draw();
16249   cSource->cd(5);
16250   hSourcePixel->Draw();
16251   cSource->cd(6);
16252   hSourceSpot->Draw();
16253 
16254   //turn off stats box
16255   gStyle->SetOptStat();
16256 
16257   TCanvas *cPmt=new TCanvas("cPmt","Pmt",0,0,1200,800);
16258   cPmt->SetFillColor(0);
16259   cPmt->Divide(2,1);
16260   cPmt->cd(1);
16261   hPmtFace->Draw("colz");
16262   cPmt->cd(2);
16263   hSpotVsPix->Draw("colz");
16264   
16265   MSG("CDAnalysis",Msg::kInfo) 
16266     <<" ** Finished ValidateXTalkHits method **"<<endl;
16267 }
16268 
16269 //......................................................................
16270 
16271 void CDAnalysis::ValidatePIDInfo()
16272 {
16273   MSG("CDAnalysis",Msg::kInfo) 
16274     <<" ** Running ValidatePIDInfo method... **"<<endl;
16275 
16276   TH1F *hNoOverlap=new TH1F("hNoOverlap","hNoOverlap",100,-2,5);
16277   hNoOverlap->GetXaxis()->SetTitle("NoOverlap");
16278   hNoOverlap->GetXaxis()->CenterTitle();
16279   hNoOverlap->GetYaxis()->SetTitle("");
16280   hNoOverlap->GetYaxis()->CenterTitle();
16281   hNoOverlap->SetFillColor(0);
16282   hNoOverlap->SetBit(TH1::kCanRebin);
16283 
16284   TH1F *hInCERTime=new TH1F("hInCERTime","hInCERTime",100,-2,20);
16285   hInCERTime->GetXaxis()->SetTitle("InCERTime");
16286   hInCERTime->GetXaxis()->CenterTitle();
16287   hInCERTime->GetYaxis()->SetTitle("");
16288   hInCERTime->GetYaxis()->CenterTitle();
16289   hInCERTime->SetFillColor(0);
16290   hInCERTime->SetBit(TH1::kCanRebin);
16291 
16292   //Undetermined kUnknown 0x00
16293   //e   kElectron 0x01
16294   //mu  kMuon 0x02
16295   //pi  kPion 0x04
16296   //K   kKaon 0x08
16297   //p   kProton 0x16
16298 
16299   TH1F *hPIDType=new TH1F("hPIDType","hPIDType",400,-2,30);
16300   hPIDType->GetXaxis()->SetTitle("PIDType");
16301   hPIDType->GetXaxis()->CenterTitle();
16302   hPIDType->GetYaxis()->SetTitle("");
16303   hPIDType->GetYaxis()->CenterTitle();
16304   hPIDType->SetFillColor(0);
16305   hPIDType->SetBit(TH1::kCanRebin);
16306 
16307   TH1F *hNoOverlapBits=new TH1F("hNoOverlapBits","hNoOverlapBits",
16308                                 400,-2,40);
16309   hNoOverlapBits->GetXaxis()->SetTitle("NoOverlapBits");
16310   hNoOverlapBits->GetXaxis()->CenterTitle();
16311   hNoOverlapBits->GetYaxis()->SetTitle("");
16312   hNoOverlapBits->GetYaxis()->CenterTitle();
16313   hNoOverlapBits->SetFillColor(0);
16314   hNoOverlapBits->SetBit(TH1::kCanRebin);
16315 
16316   TH1F *hInCERTimeBits=new TH1F("hInCERTimeBits","hInCERTimeBits",
16317                                 10,-2,3);
16318   hInCERTimeBits->GetXaxis()->SetTitle("InCERTimeBits");
16319   hInCERTimeBits->GetXaxis()->CenterTitle();
16320   hInCERTimeBits->GetYaxis()->SetTitle("");
16321   hInCERTimeBits->GetYaxis()->CenterTitle();
16322   hInCERTimeBits->SetFillColor(0);
16323   hInCERTimeBits->SetBit(TH1::kCanRebin);
16324 
16325   TH1F *hOLChi2=new TH1F("hOLChi2","hOLChi2",400,-2,20);
16326   hOLChi2->GetXaxis()->SetTitle("OLChi2");
16327   hOLChi2->GetXaxis()->CenterTitle();
16328   hOLChi2->GetYaxis()->SetTitle("");
16329   hOLChi2->GetYaxis()->CenterTitle();
16330   hOLChi2->SetFillColor(0);
16331   hOLChi2->SetBit(TH1::kCanRebin);
16332 
16333   TH1F *hTriggerPMT=new TH1F("hTriggerPMT","TriggerPMT",400,-2,30);
16334   hTriggerPMT->GetXaxis()->SetTitle("TriggerPMT");
16335   hTriggerPMT->GetXaxis()->CenterTitle();
16336   hTriggerPMT->GetYaxis()->SetTitle("");
16337   hTriggerPMT->GetYaxis()->CenterTitle();
16338   hTriggerPMT->SetFillColor(0);
16339   hTriggerPMT->SetBit(TH1::kCanRebin);
16340 
16341   TH1F *hFafErr=new TH1F("hFafErr","FafErr",400,-2,30);
16342   hFafErr->GetXaxis()->SetTitle("FafErr");
16343   hFafErr->GetXaxis()->CenterTitle();
16344   hFafErr->GetYaxis()->SetTitle("");
16345   hFafErr->GetYaxis()->CenterTitle();
16346   hFafErr->SetFillColor(0);
16347   hFafErr->SetBit(TH1::kCanRebin);
16348 
16349   TH1F *hSparseErr=new TH1F("hSparseErr","SparseErr",400,-2,30);
16350   hSparseErr->GetXaxis()->SetTitle("SparseErr");
16351   hSparseErr->GetXaxis()->CenterTitle();
16352   hSparseErr->GetYaxis()->SetTitle("");
16353   hSparseErr->GetYaxis()->CenterTitle();
16354   hSparseErr->SetFillColor(0);
16355   hSparseErr->SetBit(TH1::kCanRebin);
16356   
16357   TH1F *hTrigSource=new TH1F("hTrigSource","TrigSource",400,-2,2000);
16358   hTrigSource->GetXaxis()->SetTitle("TrigSource");
16359   hTrigSource->GetXaxis()->CenterTitle();
16360   hTrigSource->GetYaxis()->SetTitle("");
16361   hTrigSource->GetYaxis()->CenterTitle();
16362   hTrigSource->SetFillColor(0);
16363   hTrigSource->SetBit(TH1::kCanRebin);
16364 
16365   TH1F *hKovADC1=new TH1F("hKovADC1","KovADC1",400,-5,15000);
16366   hKovADC1->GetXaxis()->SetTitle("KovADC1");
16367   hKovADC1->GetXaxis()->CenterTitle();
16368   hKovADC1->GetYaxis()->SetTitle("");
16369   hKovADC1->GetYaxis()->CenterTitle();
16370   hKovADC1->SetFillColor(0);
16371   hKovADC1->SetBit(TH1::kCanRebin);
16372 
16373   TH1F *hKovADC2=new TH1F("hKovADC2","KovADC2",400,-5,15000);
16374   hKovADC2->GetXaxis()->SetTitle("KovADC2");
16375   hKovADC2->GetXaxis()->CenterTitle();
16376   hKovADC2->GetYaxis()->SetTitle("");
16377   hKovADC2->GetYaxis()->CenterTitle();
16378   hKovADC2->SetFillColor(0);
16379   hKovADC2->SetBit(TH1::kCanRebin);
16380 
16381   TH1F *hKovADC3=new TH1F("hKovADC3","KovADC3",400,-5,15000);
16382   hKovADC3->GetXaxis()->SetTitle("KovADC3");
16383   hKovADC3->GetXaxis()->CenterTitle();
16384   hKovADC3->GetYaxis()->SetTitle("");
16385   hKovADC3->GetYaxis()->CenterTitle();
16386   hKovADC3->SetFillColor(0);
16387   hKovADC3->SetBit(TH1::kCanRebin);
16388 
16389   TH1F *hKovTimeStamp1=new TH1F("hKovTimeStamp1","KovTimeStamp1",
16390                                 400,-2,30);
16391   hKovTimeStamp1->GetXaxis()->SetTitle("KovTimeStamp1");
16392   hKovTimeStamp1->GetXaxis()->CenterTitle();
16393   hKovTimeStamp1->GetYaxis()->SetTitle("");
16394   hKovTimeStamp1->GetYaxis()->CenterTitle();
16395   hKovTimeStamp1->SetFillColor(0);
16396   hKovTimeStamp1->SetBit(TH1::kCanRebin);
16397 
16398   TH1F *hKovTimeStamp2=new TH1F("hKovTimeStamp2","KovTimeStamp2",
16399                                 400,-2,30);
16400   hKovTimeStamp2->GetXaxis()->SetTitle("KovTimeStamp2");
16401   hKovTimeStamp2->GetXaxis()->CenterTitle();
16402   hKovTimeStamp2->GetYaxis()->SetTitle("");
16403   hKovTimeStamp2->GetYaxis()->CenterTitle();
16404   hKovTimeStamp2->SetFillColor(0);
16405   hKovTimeStamp2->SetBit(TH1::kCanRebin);
16406 
16407   TH1F *hKovTimeStamp3=new TH1F("hKovTimeStamp3","KovTimeStamp3",
16408                                 400,-2,30);
16409   hKovTimeStamp3->GetXaxis()->SetTitle("KovTimeStamp3");
16410   hKovTimeStamp3->GetXaxis()->CenterTitle();
16411   hKovTimeStamp3->GetYaxis()->SetTitle("");
16412   hKovTimeStamp3->GetYaxis()->CenterTitle();
16413   hKovTimeStamp3->SetFillColor(0);
16414   hKovTimeStamp3->SetBit(TH1::kCanRebin);
16415 
16416   TH1F *hSnarlTimeFrame=new TH1F("hSnarlTimeFrame","SnarlTimeFrame",
16417                                  400,-2,30);
16418   hSnarlTimeFrame->GetXaxis()->SetTitle("SnarlTimeFrame");
16419   hSnarlTimeFrame->GetXaxis()->CenterTitle();
16420   hSnarlTimeFrame->GetYaxis()->SetTitle("");
16421   hSnarlTimeFrame->GetYaxis()->CenterTitle();
16422   hSnarlTimeFrame->SetFillColor(0);
16423   hSnarlTimeFrame->SetBit(TH1::kCanRebin);
16424 
16425   TH1F *hSnarlMinTimeStamp=new TH1F("hSnarlMinTimeStamp",
16426                                     "SnarlMinTimeStamp",400,-2,30);
16427   hSnarlMinTimeStamp->GetXaxis()->SetTitle("SnarlMinTimeStamp");
16428   hSnarlMinTimeStamp->GetXaxis()->CenterTitle();
16429   hSnarlMinTimeStamp->GetYaxis()->SetTitle("");
16430   hSnarlMinTimeStamp->GetYaxis()->CenterTitle();
16431   hSnarlMinTimeStamp->SetFillColor(0);
16432   hSnarlMinTimeStamp->SetBit(TH1::kCanRebin);
16433 
16434   TH1F *hSnarlMaxTimeStamp=new TH1F("hSnarlMaxTimeStamp",
16435                                     "SnarlMaxTimeStamp",400,-2,30);
16436   hSnarlMaxTimeStamp->GetXaxis()->SetTitle("SnarlMaxTimeStamp");
16437   hSnarlMaxTimeStamp->GetXaxis()->CenterTitle();
16438   hSnarlMaxTimeStamp->GetYaxis()->SetTitle("");
16439   hSnarlMaxTimeStamp->GetYaxis()->CenterTitle();
16440   hSnarlMaxTimeStamp->SetFillColor(0);
16441   hSnarlMaxTimeStamp->SetBit(TH1::kCanRebin);
16442 
16443   TH1F *hTofTDC0=new TH1F("hTofTDC0","TofTDC0",400,-2,4000);
16444   hTofTDC0->GetXaxis()->SetTitle("TofTDC0");
16445   hTofTDC0->GetXaxis()->CenterTitle();
16446   hTofTDC0->GetYaxis()->SetTitle("");
16447   hTofTDC0->GetYaxis()->CenterTitle();
16448   hTofTDC0->SetFillColor(0);
16449   hTofTDC0->SetBit(TH1::kCanRebin);
16450 
16451   TH1F *hTofTDC1=new TH1F("hTofTDC1","TofTDC1",400,-2,4000);
16452   hTofTDC1->GetXaxis()->SetTitle("TofTDC1");
16453   hTofTDC1->GetXaxis()->CenterTitle();
16454   hTofTDC1->GetYaxis()->SetTitle("");
16455   hTofTDC1->GetYaxis()->CenterTitle();
16456   hTofTDC1->SetFillColor(0);
16457   hTofTDC1->SetBit(TH1::kCanRebin);
16458 
16459   TH1F *hTofTDC2=new TH1F("hTofTDC2","TofTDC2",400,-2,4000);
16460   hTofTDC2->GetXaxis()->SetTitle("TofTDC2");
16461   hTofTDC2->GetXaxis()->CenterTitle();
16462   hTofTDC2->GetYaxis()->SetTitle("");
16463   hTofTDC2->GetYaxis()->CenterTitle();
16464   hTofTDC2->SetFillColor(0);
16465   hTofTDC2->SetBit(TH1::kCanRebin);
16466 
16467   TH1F *hTofADC0=new TH1F("hTofADC0","TofADC0",400,-2,30);
16468   hTofADC0->GetXaxis()->SetTitle("TofADC0");
16469   hTofADC0->GetXaxis()->CenterTitle();
16470   hTofADC0->GetYaxis()->SetTitle("");
16471   hTofADC0->GetYaxis()->CenterTitle();
16472   hTofADC0->SetFillColor(0);
16473   hTofADC0->SetBit(TH1::kCanRebin);
16474 
16475   TH1F *hTofADC1=new TH1F("hTofADC1","TofADC1",400,-2,30);
16476   hTofADC1->GetXaxis()->SetTitle("TofADC1");
16477   hTofADC1->GetXaxis()->CenterTitle();
16478   hTofADC1->GetYaxis()->SetTitle("");
16479   hTofADC1->GetYaxis()->CenterTitle();
16480   hTofADC1->SetFillColor(0);
16481   hTofADC1->SetBit(TH1::kCanRebin);
16482 
16483   TH1F *hTofADC2=new TH1F("hTofADC2","TofADC2",400,-2,30);
16484   hTofADC2->GetXaxis()->SetTitle("TofADC2");
16485   hTofADC2->GetXaxis()->CenterTitle();
16486   hTofADC2->GetYaxis()->SetTitle("");
16487   hTofADC2->GetYaxis()->CenterTitle();
16488   hTofADC2->SetFillColor(0);
16489   hTofADC2->SetBit(TH1::kCanRebin);
16490 
16491   TH1F *hTofADCTimeStamp0=new TH1F("hTofADCTimeStamp0",
16492                                    "TofADCTimeStamp",400,-2,30);
16493   hTofADCTimeStamp0->GetXaxis()->SetTitle("TofADCTimeStamp");
16494   hTofADCTimeStamp0->GetXaxis()->CenterTitle();
16495   hTofADCTimeStamp0->GetYaxis()->SetTitle("");
16496   hTofADCTimeStamp0->GetYaxis()->CenterTitle();
16497   hTofADCTimeStamp0->SetFillColor(0);
16498   hTofADCTimeStamp0->SetBit(TH1::kCanRebin);
16499 
16500   TH1F *hTofADCTimeStamp1=new TH1F("hTofADCTimeStamp1",
16501                                    "TofADCTimeStamp1",400,-2,30);
16502   hTofADCTimeStamp1->GetXaxis()->SetTitle("TofADCTimeStamp1");
16503   hTofADCTimeStamp1->GetXaxis()->CenterTitle();
16504   hTofADCTimeStamp1->GetYaxis()->SetTitle("");
16505   hTofADCTimeStamp1->GetYaxis()->CenterTitle();
16506   hTofADCTimeStamp1->SetFillColor(0);
16507   hTofADCTimeStamp1->SetBit(TH1::kCanRebin);
16508 
16509   TH1F *hTofADCTimeStamp2=new TH1F("hTofADCTimeStamp2",
16510                                    "TofADCTimeStamp2",400,-2,30);
16511   hTofADCTimeStamp2->GetXaxis()->SetTitle("TofADCTimeStamp2");
16512   hTofADCTimeStamp2->GetXaxis()->CenterTitle();
16513   hTofADCTimeStamp2->GetYaxis()->SetTitle("");
16514   hTofADCTimeStamp2->GetYaxis()->CenterTitle();
16515   hTofADCTimeStamp2->SetFillColor(0);
16516   hTofADCTimeStamp2->SetBit(TH1::kCanRebin);
16517 
16518   TH1F *hTofTimeStamp=new TH1F("hTofTimeStamp",
16519                                "TofTimeStamp",400,-2,30);
16520   hTofTimeStamp->GetXaxis()->SetTitle("TofTimeStamp");
16521   hTofTimeStamp->GetXaxis()->CenterTitle();
16522   hTofTimeStamp->GetYaxis()->SetTitle("");
16523   hTofTimeStamp->GetYaxis()->CenterTitle();
16524   hTofTimeStamp->SetFillColor(0);
16525   hTofTimeStamp->SetBit(TH1::kCanRebin);
16526 
16527   TH1F *hTickSinceLast=new TH1F("hTickSinceLast",
16528                                 "TickSinceLast",400,-2,30);
16529   hTickSinceLast->GetXaxis()->SetTitle("TickSinceLast");
16530   hTickSinceLast->GetXaxis()->CenterTitle();
16531   hTickSinceLast->GetYaxis()->SetTitle("");
16532   hTickSinceLast->GetYaxis()->CenterTitle();
16533   hTickSinceLast->SetFillColor(0);
16534   hTickSinceLast->SetBit(TH1::kCanRebin);
16535 
16536   Bool_t triggerPMT;            //Did the triggerPMT fire?
16537   Bool_t fafErr;                //Faf errors?
16538   Bool_t sparseErr;             //sparse errors?
16539   Int_t trigSource;             //trigger source
16540   Int_t kovADC1;                //Cerenkov ADC value
16541   Int_t kovTimeStamp1;          //Cerenkov TimeStamp
16542   Int_t kovADC2;
16543   Int_t kovTimeStamp2;
16544   Int_t kovADC3;
16545   Int_t kovTimeStamp3;
16546   Int_t snarlTimeFrame;         //Event TimeFrame
16547   ULong_t snarlMinTimeStamp;  //event minimum timetimestamp
16548   ULong_t snarlMaxTimeStamp;  //event maximum timestamp
16549   Int_t tofTDC0;                //TOF tdc0 value
16550   Int_t tofTDC1;                //TOF tdc1 value
16551   Int_t tofTDC2;                //TOF tdc2 value
16552   Int_t tofADC0;                //TOF ADC0 value (not always present) 
16553                                //______Context depends on the run
16554   Int_t tofADC1;                //TOF ADC1 value (not always present) 
16555                                //Used for tof system testing
16556   Int_t tofADC2;                //TOF ADC1 value (not always present) 
16557                                //Used for tof system testing
16558   Int_t tofADCTimeStamp0;       //tof adc timestamps
16559   Int_t tofADCTimeStamp1;
16560   Int_t tofADCTimeStamp2;  
16561   Int_t tofTimeStamp;           //time stamp of TOF readout
16562   Int_t tickSinceLast;          //Ticks since last snarl
16563 
16564   //pid validation counters
16565   Int_t myPiMuCounter=0;
16566   Int_t pidPiMuCounter=0;
16567   Int_t myElecCounter=0;
16568   Int_t pidElecCounter=0;
16569   Int_t bothPiMuCounter=0;
16570   Int_t bothElecCounter=0;
16571 
16572   MSG("CDAnalysis",Msg::kInfo)<<"Starting main loop..."<<endl;
16573 
16577   
16578   this->InitialiseLoopVariables();  
16579   
16580   for(Int_t event=0;event<fEvents;event++){
16581     
16582     this->SetLoopVariables(event);
16583 
16584     if (!fPIDInfo){
16585       MAXMSG("CDAnalysis",Msg::kWarning,100)
16586         <<"No PID info: fPIDInfo="<<fPIDInfo<<endl;
16587       continue;
16588     }
16589     
16590     //bool for storing results of pid
16591     Bool_t myPiMuFound=false;
16592     Bool_t pidPiMuFound=false;
16593     Bool_t myElecFound=false;
16594     Bool_t pidElecFound=false;
16595 
16596     if (!this->CutByHandOnPid()){
16597       myPiMuCounter++;
16598       myPiMuFound=true;
16599     }
16600     if (!this->CutOnPid()){
16601       pidPiMuCounter++;
16602       pidPiMuFound=true;
16603     }
16604     if (!this->CutByHandOnPidForElec()){
16605       myElecCounter++;
16606       myElecFound=true;
16607     }
16608     if (!this->CutOnPidForElec()){//only electrons!
16609       pidElecCounter++;
16610       pidElecFound=true;
16611     }
16612 
16613     if (myPiMuFound && pidPiMuFound) bothPiMuCounter++;
16614     if (myElecFound && pidElecFound) bothElecCounter++;
16615 
16616     //if (!fPIDInfo->IsEmpty()){
16617     
16618       triggerPMT=fPIDInfo->GetTriggerPMT();
16619       fafErr=fPIDInfo->GetFafErr() ;
16620       sparseErr=fPIDInfo->GetSparseErr();
16621       trigSource=fPIDInfo->GetTrigSource();
16622       kovADC1=fPIDInfo->GetKovADC1() ;
16623       kovTimeStamp1=fPIDInfo->GetKovTimeStamp1();
16624       kovADC2=fPIDInfo->GetKovADC2();
16625       kovTimeStamp2=fPIDInfo->GetKovTimeStamp2();
16626       kovADC3=fPIDInfo->GetKovADC3();
16627       kovTimeStamp3=fPIDInfo->GetKovTimeStamp3(); 
16628       snarlTimeFrame=fPIDInfo->GetSnarlTimeFrame();
16629       snarlMinTimeStamp=fPIDInfo->GetSnarlMinTimeStamp();
16630       snarlMaxTimeStamp=fPIDInfo->GetSnarlMaxTimeStamp();
16631       tofTDC0=fPIDInfo->GetTofTDC0();
16632       tofTDC1=fPIDInfo->GetTofTDC1();
16633       tofTDC2=fPIDInfo->GetTofTDC2();
16634       tofADC0=fPIDInfo->GetTofADC0();
16635       tofADC1=fPIDInfo->GetTofADC1();
16636       tofADC2=fPIDInfo->GetTofADC2();
16637       tofADCTimeStamp0=fPIDInfo->GetTofADCTimeStamp0();
16638       tofADCTimeStamp1=fPIDInfo->GetTofADCTimeStamp1();
16639       tofADCTimeStamp2=fPIDInfo->GetTofADCTimeStamp2();
16640       tofTimeStamp=fPIDInfo->GetTofTimeStamp();
16641       tickSinceLast=fPIDInfo->GetTickSinceLast();
16642 
16643       //get and fill the CalDetPID info
16644       hNoOverlap->Fill(fPIDInfo->GetNoOverlap());
16645       hInCERTime->Fill(fPIDInfo->GetInCERTime());
16646       hPIDType->Fill(fPIDInfo->GetPIDType());
16647       hNoOverlapBits->Fill(fPIDInfo->GetNoOverlapBits());
16648       hInCERTimeBits->Fill(fPIDInfo->GetInCERTimeBits());
16649       hOLChi2->Fill(fPIDInfo->GetOLChi2());
16650 
16651       hTriggerPMT->Fill(triggerPMT);
16652       hFafErr->Fill(fafErr);
16653       hSparseErr->Fill(sparseErr);
16654       hTrigSource->Fill(trigSource);
16655       hKovADC1->Fill(kovADC1);
16656       hKovTimeStamp1->Fill(kovTimeStamp1);
16657       hKovADC2->Fill(kovADC2);
16658       hKovTimeStamp2->Fill(kovTimeStamp2);
16659       hKovADC3->Fill(kovADC3);
16660       hKovTimeStamp3->Fill(kovTimeStamp3);
16661       hSnarlTimeFrame->Fill(snarlTimeFrame);
16662       hSnarlMinTimeStamp->Fill(snarlMinTimeStamp);
16663       hSnarlMaxTimeStamp->Fill(snarlMaxTimeStamp);
16664       hTofTDC0->Fill(tofTDC0);
16665       hTofTDC1->Fill(tofTDC1);
16666       hTofTDC2->Fill(tofTDC2);
16667       hTofADC0->Fill(tofADC0);
16668       hTofADC1->Fill(tofADC1);
16669       hTofADC2->Fill(tofADC2);
16670       hTofADCTimeStamp0->Fill(tofADCTimeStamp0);
16671       hTofADCTimeStamp1->Fill(tofADCTimeStamp1);
16672       hTofADCTimeStamp2->Fill(tofADCTimeStamp2);
16673       hTofTimeStamp->Fill(tofTimeStamp);
16674       hTickSinceLast->Fill(tickSinceLast);
16675 
16676       //}
16677 
16678   }//end of for                                       
16679   
16683 
16684   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
16685 
16686   TCanvas *cTof=new TCanvas("cTof","cTof",0,0,1200,800);
16687   cTof->SetFillColor(0);
16688   cTof->Divide(3,3);
16689   cTof->cd(1);
16690   hTofTDC0->Draw();
16691   cTof->cd(2);
16692   hTofTDC1->Draw();
16693   cTof->cd(3);
16694   hTofTDC2->Draw();
16695   cTof->cd(1+3);
16696   hTofADC0->Draw();
16697   cTof->cd(2+3);
16698   hTofADC1->Draw();
16699   cTof->cd(3+3);
16700   hTofADC2->Draw();
16701   cTof->cd(1+6);
16702   hTofADCTimeStamp0->Draw();
16703   cTof->cd(2+6);
16704   hTofADCTimeStamp1->Draw();
16705   cTof->cd(3+6);
16706   hTofADCTimeStamp2->Draw();
16707 
16708   TCanvas *cKov=new TCanvas("cKov","cKov",0,0,1200,800);
16709   cKov->SetFillColor(0);
16710   cKov->Divide(3,2);
16711   cKov->cd(1);
16712   hKovADC1->Draw();
16713   cKov->cd(2);
16714   hKovADC2->Draw();
16715   cKov->cd(3);
16716   hKovADC3->Draw();
16717   cKov->cd(1+3);
16718   hKovTimeStamp1->Draw();
16719   cKov->cd(2+3);
16720   hKovTimeStamp2->Draw();
16721   cKov->cd(3+3);
16722   hKovTimeStamp3->Draw();
16723 
16724   TCanvas *cTime=new TCanvas("cTime","cTime",0,0,1200,800);
16725   cTime->SetFillColor(0);
16726   cTime->Divide(2,1);
16727   cTime->cd(1);
16728   hTofTimeStamp->Draw();
16729   cTime->cd(2);
16730   hTickSinceLast->Draw();
16731 
16732   TCanvas *cTrig=new TCanvas("cTrig","cTrig",0,0,1200,800);
16733   cTrig->SetFillColor(0);
16734   cTrig->Divide(2,1);
16735   cTrig->cd(1);
16736   hTriggerPMT->Draw();
16737   cTrig->cd(2);
16738   hTrigSource->Draw();
16739 
16740   TCanvas *cErr=new TCanvas("cErr","cErr",0,0,1200,800);
16741   cErr->SetFillColor(0);
16742   cErr->Divide(2,1);
16743   cErr->cd(1);
16744   hFafErr->Draw();
16745   cErr->cd(2);
16746   hSparseErr->Draw();
16747 
16748   TCanvas *cPID=new TCanvas("cPID","cPID",0,0,1200,800);
16749   cPID->SetFillColor(0);
16750   cPID->Divide(3,2);
16751   cPID->cd(1);
16752   hNoOverlap->Draw();
16753   cPID->cd(2);
16754   hInCERTime->Draw();
16755   cPID->cd(3);
16756   hPIDType->Draw();
16757   cPID->cd(4);
16758   hNoOverlapBits->Draw();
16759   cPID->cd(5);
16760   hInCERTimeBits->Draw();
16761   cPID->cd(6);
16762   hOLChi2->Draw();
16763 
16764   //pid validation counters results
16765   MSG("CDAnalysis",Msg::kInfo)
16766     <<"My PiMu counter="<<myPiMuCounter<<endl
16767     <<"PID PiMu counter="<<pidPiMuCounter<<endl
16768     <<"Both PiMu counter="<<bothPiMuCounter<<endl
16769     <<"My Elec counter="<<myElecCounter<<endl
16770     <<"PID Elec counter="<<pidElecCounter<<endl
16771     <<"Both Elec counter="<<bothElecCounter<<endl;
16772 
16773   MSG("CDAnalysis",Msg::kInfo) 
16774     <<" ** Finished ValidatePIDInfo method **"<<endl;
16775 }
16776 
16777 //......................................................................
16778 
16779 void CDAnalysis::PrintPIDStats()
16780 {
16781   MSG("CDAnalysis",Msg::kInfo) 
16782     <<" ** Running PrintPIDStats method... **"<<endl;
16783 
16784   //pid counters
16785   fMyPiMuCounter=0;
16786   fPidPiMuCounter=0;
16787   fMyElecCounter=0;
16788   fPidElecCounter=0;
16789   fBothPiMuCounter=0;
16790   fBothElecCounter=0;
16791 
16792   MSG("CDAnalysis",Msg::kInfo)<<"Starting main loop..."<<endl;
16793 
16797   
16798   this->InitialiseLoopVariables();  
16799   
16800   for(Int_t event=0;event<fEvents;event++){
16801     
16802     this->SetLoopVariables(event);
16803 
16804     if (this->CutOnDeadChips()) continue;
16805 
16806     if (!fPIDInfo){
16807       MAXMSG("CDAnalysis",Msg::kWarning,100)
16808         <<"No PID info: fPIDInfo="<<fPIDInfo<<endl;
16809       continue;
16810     }
16811     
16812     //bool for storing results of pid
16813     Bool_t myPiMuFound=false;
16814     Bool_t pidPiMuFound=false;
16815     Bool_t myElecFound=false;
16816     Bool_t pidElecFound=false;
16817 
16818     if (!this->CutByHandOnPid()){
16819       fMyPiMuCounter++;
16820       myPiMuFound=true;
16821     }
16822     if (!this->CutOnPid()){
16823       fPidPiMuCounter++;
16824       pidPiMuFound=true;
16825     }
16826     if (!this->CutByHandOnPidForElec()){
16827       fMyElecCounter++;
16828       myElecFound=true;
16829     }
16830     if (!this->CutOnPidForElec()){//only electrons!
16831       fPidElecCounter++;
16832       pidElecFound=true;
16833     }
16834 
16835     if (myPiMuFound && pidPiMuFound) fBothPiMuCounter++;
16836     if (myElecFound && pidElecFound) fBothElecCounter++;
16837 
16838   }//end of for                                       
16839   
16843 
16844   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
16845 
16846   //pid validation counters results
16847   MSG("CDAnalysis",Msg::kInfo)
16848     <<"My PiMu counter="<<fMyPiMuCounter<<endl
16849     <<"PID PiMu counter="<<fPidPiMuCounter<<endl
16850     <<"Both PiMu counter="<<fBothPiMuCounter<<endl
16851     <<"My Elec counter="<<fMyElecCounter<<endl
16852     <<"PID Elec counter="<<fPidElecCounter<<endl
16853     <<"Both Elec counter="<<fBothElecCounter<<endl;
16854 
16855   MSG("CDAnalysis",Msg::kInfo) 
16856     <<" ** Finished PrintPIDStats method **"<<endl;
16857 }
16858 
16859 //......................................................................
16860 
16861 void CDAnalysis::Template()
16862 {
16863   MSG("CDAnalysis",Msg::kInfo) 
16864     <<endl<<" ** Running the TEMPLATE!!!! method... ** "<<endl;
16865 
16867   //put any variable and histogram declarations etc here
16869 
16870   TH1F *hEvent=new TH1F("hEvent","Event",40,-5,35);
16871   hEvent->GetXaxis()->SetTitle("Event");
16872   hEvent->GetXaxis()->CenterTitle();
16873   hEvent->GetYaxis()->SetTitle("Num");
16874   hEvent->GetYaxis()->CenterTitle();
16875   hEvent->SetFillColor(0);
16876   hEvent->SetBit(TH1::kCanRebin);
16877 
16881   
16882   this->InitialiseLoopVariables();  
16883   
16884   for(Int_t event=0;event<fEvents;event++){
16885     
16886     this->SetLoopVariables(event);
16887 
16889     //put all your cuts and histogram filling here
16891     
16892     MSG("CDAnalysis",Msg::kVerbose)
16893         <<"Event="<<event<<endl;
16894     
16895     hEvent->Fill(event);
16896 
16897   }//end of for                                       
16898   
16902 
16903   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
16904 
16906   //do any plots or analysis here
16908 
16909   TCanvas *cMean=new TCanvas("cMean","Mean adc",0,0,1200,800);
16910   cMean->SetFillColor(0);
16911   cMean->cd();
16912   hEvent->Draw();
16913 
16914   MSG("CDAnalysis",Msg::kInfo) 
16915     <<endl<<" ** Finished the TEMPLATE!!!!! method ** "<<endl;
16916 }
16917 
16918 //......................................................................
16919 
16920 void CDAnalysis::ValidateMC()
16921 {
16922   MSG("CDAnalysis",Msg::kInfo) 
16923     <<" ** Running ValidateMC method... **"<<endl;
16924 
16925   fS="Strip Vs Plane SigCor (SE1)";
16926   TProfile2D* pStVsPl1=new TProfile2D("pStVsPl1",fS.c_str(),
16927                                            64,-2,62,30,-3,27);
16928   pStVsPl1->GetXaxis()->SetTitle("Plane");
16929   pStVsPl1->GetXaxis()->CenterTitle();
16930   pStVsPl1->GetYaxis()->SetTitle("Strip");
16931   pStVsPl1->GetYaxis()->CenterTitle();
16932   pStVsPl1->SetFillColor(0);
16933   //pStVsPl1->SetMaximum(15000);
16934 
16935   fS="Strip Vs Plane SigCor (SE2)";
16936   TProfile2D* pStVsPl2=new TProfile2D("pStVsPl2",fS.c_str(),
16937                                            64,-2,62,30,-3,27);
16938   pStVsPl2->GetXaxis()->SetTitle("Plane");
16939   pStVsPl2->GetXaxis()->CenterTitle();
16940   pStVsPl2->GetYaxis()->SetTitle("Strip");
16941   pStVsPl2->GetYaxis()->CenterTitle();
16942   pStVsPl2->SetFillColor(0);
16943   //pStVsPl2->SetMaximum(15000);
16944 
16945   fS="Strip Vs Plane PE (SE1)";
16946   TProfile2D* pStVsPlPe1=new TProfile2D("pStVsPlPe1",fS.c_str(),
16947                                            64,-2,62,30,-3,27);
16948   pStVsPlPe1->GetXaxis()->SetTitle("Plane");
16949   pStVsPlPe1->GetXaxis()->CenterTitle();
16950   pStVsPlPe1->GetYaxis()->SetTitle("Strip");
16951   pStVsPlPe1->GetYaxis()->CenterTitle();
16952   pStVsPlPe1->SetFillColor(0);
16953   //pStVsPlPe1->SetMaximum(15000);
16954 
16955   fS="Strip Vs Plane SigCor (SE2)";
16956   TProfile2D* pStVsPlPe2=new TProfile2D("pStVsPlPe2",fS.c_str(),
16957                                            64,-2,62,30,-3,27);
16958   pStVsPlPe2->GetXaxis()->SetTitle("Plane");
16959   pStVsPlPe2->GetXaxis()->CenterTitle();
16960   pStVsPlPe2->GetYaxis()->SetTitle("Strip");
16961   pStVsPlPe2->GetYaxis()->CenterTitle();
16962   pStVsPlPe2->SetFillColor(0);
16963   //pStVsPlPe2->SetMaximum(15000);
16964 
16965 
16969   
16970   this->InitialiseLoopVariables();  
16971   
16972   for(Int_t event=0;event<fEvents;event++){
16973     
16974     this->SetLoopVariables(event);
16975 
16976     //get tclones arrays for this snarl
16977     //TClonesArray &cTrk=*fTrkHitInfo;
16978     Int_t numTrkHits=fTrkHitInfo->GetEntries();
16979     TClonesArray &cUnTrk = *fUnTrkHitInfo;
16980     Int_t numUnTrkHits = fUnTrkHitInfo->GetEntries();
16981     //CDTrackedHitInfo *trackedHitInfo=(CDTrackedHitInfo*) c[hit];
16982     //TClonesArray &cXTalk = *fXTalkHits;
16983     Int_t numXTalkHits=fXTalkHits->GetEntries();
16984     //TClonesArray &cTruth = *fTruthHitInfo;
16985     Int_t numTruthHits=0;
16986     if (fTruthHitInfo) numTruthHits=fTruthHitInfo->GetEntries();
16987 
16988     MSG("CDAnalysis",Msg::kInfo)
16989       <<"Event="<<event
16990       <<", Num hits: trk="<<numTrkHits<<", unTrk="<<numUnTrkHits
16991       <<", xtalk="<<numXTalkHits<<", truth="<<numTruthHits
16992       <<endl;
16993 
16995     //loop over the untracked hits in the snarl
16997     for (Int_t hit=0;hit<numUnTrkHits;hit++){
16998       //cast the tclonesarray up to a trackedhitinfo object
16999       CDTrackedHitInfo *hitInfo=
17000         dynamic_cast<CDTrackedHitInfo*>(cUnTrk[hit]);
17001 
17002       this->ReadInHitInfo(hitInfo);
17003 
17004       //fill the histo
17005       if (fStripend==1) pStVsPl1->Fill(fPlane,fStrip,fChargeSigCor);
17006       if (fStripend==2) pStVsPl2->Fill(fPlane,fStrip,fChargeSigCor);
17007 
17008       if (fStripend==1) pStVsPlPe1->Fill(fPlane,fStrip,fChargePe);
17009       if (fStripend==2) pStVsPlPe2->Fill(fPlane,fStrip,fChargePe);
17010       
17011     }
17012   }//end of for                                       
17013   
17017 
17018   //turn off the stats box printing
17019   gStyle->SetOptStat(0);
17020 
17021   TCanvas *cStVsPl=new TCanvas("cStVsPl","StVsPl",
17022                                          0,0,1200,800);
17023   cStVsPl->SetFillColor(0);
17024   cStVsPl->Divide(1,2);
17025   cStVsPl->cd(1);
17026   pStVsPl1->Draw("colz");
17027   cStVsPl->cd(2);
17028   pStVsPl2->Draw("colz");
17029 
17030   TCanvas *cStVsPlPe=new TCanvas("cStVsPlPe","StVsPlPe",
17031                                          0,0,1200,800);
17032   cStVsPlPe->SetFillColor(0);
17033   cStVsPlPe->Divide(1,2);
17034   cStVsPlPe->cd(1);
17035   pStVsPlPe1->Draw("colz");
17036   cStVsPlPe->cd(2);
17037   pStVsPlPe2->Draw("colz");
17038 
17039   MSG("CDAnalysis",Msg::kInfo) 
17040     <<" ** Finished ValidateMC method **"<<endl;
17041 }
17042 
17043 //......................................................................
17044 
17045 void CDAnalysis::TruthAnalysis()
17046 {
17047   MSG("CDAnalysis",Msg::kInfo) 
17048     <<" ** Running TruthAnalysis method... **"<<endl;
17049   
17050   TH1F *hStrip=new TH1F("hStrip","Strips hit",100,-2,30);
17051   hStrip->GetXaxis()->SetTitle("Strip");
17052   hStrip->GetXaxis()->CenterTitle();
17053   hStrip->GetYaxis()->SetTitle("");
17054   hStrip->GetYaxis()->CenterTitle();
17055   hStrip->SetFillColor(0);
17056   hStrip->SetBit(TH1::kCanRebin);
17057 
17058   TH1F *hPlane=new TH1F("hPlane","Planes hit",200,-2,75);
17059   hPlane->GetXaxis()->SetTitle("Plane");
17060   hPlane->GetXaxis()->CenterTitle();
17061   hPlane->GetYaxis()->SetTitle("");
17062   hPlane->GetYaxis()->CenterTitle();
17063   hPlane->SetFillColor(0);
17064   hPlane->SetBit(TH1::kCanRebin);
17065 
17066   TH1F *hPmtTruth1=new TH1F("hPmtTruth1","PmtTruth1",400,-2,125);
17067   hPmtTruth1->GetXaxis()->SetTitle("PmtTruth1");
17068   hPmtTruth1->GetXaxis()->CenterTitle();
17069   hPmtTruth1->GetYaxis()->SetTitle("");
17070   hPmtTruth1->GetYaxis()->CenterTitle();
17071   hPmtTruth1->SetFillColor(0);
17072   hPmtTruth1->SetBit(TH1::kCanRebin);
17073 
17074   TH1F *hPmtTruth2=new TH1F("hPmtTruth2","PmtTruth2",400,-2,125);
17075   hPmtTruth2->GetXaxis()->SetTitle("PmtTruth2");
17076   hPmtTruth2->GetXaxis()->CenterTitle();
17077   hPmtTruth2->GetYaxis()->SetTitle("");
17078   hPmtTruth2->GetYaxis()->CenterTitle();
17079   hPmtTruth2->SetFillColor(0);
17080   hPmtTruth2->SetBit(TH1::kCanRebin);
17081   //kUnknown       = 0x00,   // Can happen: known cause is 0 charge
17082   // but random noise passes sparsification thresh.
17083   //kGenuine       = 0x01,   // A real hit from real gosh-darn physics.
17084   //kDarkNoise        = 0x02,   // Dark noise from the tube.
17085   //kFibreLight       = 0x04,   // Random [singles] from a fibre. 
17086   //kCrosstalk        = 0x08,   // A generic crosstalk hit.
17087   //kCrosstalkOptical = 0x10,   // A crosstalk hit, specifically from
17088   //kLeakFromNextBucket = 0x20,  
17089   // The next bucket leaked charge back to this one
17090   //kLeakFromPrevBucket = 0x40  
17091 
17092   TH1F *hVaChip1=new TH1F("hVaChip1","VaChip1",50,-2,5);
17093   hVaChip1->GetXaxis()->SetTitle("VaChip1");
17094   hVaChip1->GetXaxis()->CenterTitle();
17095   hVaChip1->GetYaxis()->SetTitle("");
17096   hVaChip1->GetYaxis()->CenterTitle();
17097   hVaChip1->SetFillColor(0);
17098   hVaChip1->SetBit(TH1::kCanRebin);
17099 
17100   TH1F *hVaChip2=new TH1F("hVaChip2","VaChip2",50,-2,5);
17101   hVaChip2->GetXaxis()->SetTitle("VaChip2");
17102   hVaChip2->GetXaxis()->CenterTitle();
17103   hVaChip2->GetYaxis()->SetTitle("");
17104   hVaChip2->GetYaxis()->CenterTitle();
17105   hVaChip2->SetFillColor(0);
17106   hVaChip2->SetBit(TH1::kCanRebin);
17107 
17108   TH1F *hMainParticle=new TH1F("hMainParticle","MainParticle",200,-20,20);
17109   hMainParticle->GetXaxis()->SetTitle("MainParticle");
17110   hMainParticle->GetXaxis()->CenterTitle();
17111   hMainParticle->GetYaxis()->SetTitle("");
17112   hMainParticle->GetYaxis()->CenterTitle();
17113   hMainParticle->SetFillColor(0);
17114   hMainParticle->SetBit(TH1::kCanRebin);
17115 
17116   TH1F *hTotalEnDep=new TH1F("hTotalEnDep","TotalEnDep",
17117                              2000,-5./1000,15./1000);
17118   hTotalEnDep->GetXaxis()->SetTitle("TotalEnDep");
17119   hTotalEnDep->GetXaxis()->CenterTitle();
17120   hTotalEnDep->GetYaxis()->SetTitle("");
17121   hTotalEnDep->GetYaxis()->CenterTitle();
17122   hTotalEnDep->SetFillColor(0);
17123   hTotalEnDep->SetBit(TH1::kCanRebin);
17124 
17125   TH1F *hMainPartEn=new TH1F("hMainPartEn","MainPartEn",500,-0.5,2);
17126   hMainPartEn->GetXaxis()->SetTitle("MainPartEn");
17127   hMainPartEn->GetXaxis()->CenterTitle();
17128   hMainPartEn->GetYaxis()->SetTitle("");
17129   hMainPartEn->GetYaxis()->CenterTitle();
17130   hMainPartEn->SetFillColor(0);
17131   hMainPartEn->SetBit(TH1::kCanRebin);
17132 
17133   TH1F *hMainPathLength=new TH1F("hMainPathLength","MainPathLength",
17134                                  500,-0.01,0.1);
17135   hMainPathLength->GetXaxis()->SetTitle("MainPathLength");
17136   hMainPathLength->GetXaxis()->CenterTitle();
17137   hMainPathLength->GetYaxis()->SetTitle("");
17138   hMainPathLength->GetYaxis()->CenterTitle();
17139   hMainPathLength->SetFillColor(0);
17140   hMainPathLength->SetBit(TH1::kCanRebin);
17141 
17142   fS="Strip Vs Plane EnergyDep Map";
17143   TProfile2D* pStVsPlEnDep=new TProfile2D(fS.c_str(),fS.c_str(),
17144                                            64,-2,62,30,-3,27);
17145   pStVsPlEnDep->GetXaxis()->SetTitle("Plane");
17146   pStVsPlEnDep->GetXaxis()->CenterTitle();
17147   pStVsPlEnDep->GetYaxis()->SetTitle("Strip");
17148   pStVsPlEnDep->GetYaxis()->CenterTitle();
17149   pStVsPlEnDep->SetFillColor(0);
17150   //pStVsPlEnDep->SetMaximum(15000);
17151 
17152   fS="Strip Vs Plane Num Hits Map";
17153   TProfile2D* hStVsPlNum=new TProfile2D(fS.c_str(),fS.c_str(),64,-2,62,30,-3,27);
17154   hStVsPlNum->GetXaxis()->SetTitle("Plane");
17155   hStVsPlNum->GetXaxis()->CenterTitle();
17156   hStVsPlNum->GetYaxis()->SetTitle("Strip");
17157   hStVsPlNum->GetYaxis()->CenterTitle();
17158   hStVsPlNum->SetFillColor(0);
17159   //hStVsPlNum->SetMaximum(15000);
17160 
17161   fS="Strip Vs Plane FibreLight Map SE1";
17162   TProfile2D* hStVsPlFibreLight1=new TProfile2D(fS.c_str(),fS.c_str(),
17163                                            64,-2,62,30,-3,27);
17164   hStVsPlFibreLight1->GetXaxis()->SetTitle("Plane");
17165   hStVsPlFibreLight1->GetXaxis()->CenterTitle();
17166   hStVsPlFibreLight1->GetYaxis()->SetTitle("Strip");
17167   hStVsPlFibreLight1->GetYaxis()->CenterTitle();
17168   hStVsPlFibreLight1->SetFillColor(0);
17169   //hStVsPlFibreLight1->SetMaximum(15000);
17170 
17171   fS="Strip Vs Plane OpticalXTalk Map SE1";
17172   TH2F* hStVsPlOptXTalk1=new TH2F("hStVsPlOptXTalk1",fS.c_str(),
17173                                   64,-2,62,30,-3,27);
17174   hStVsPlOptXTalk1->GetXaxis()->SetTitle("Plane");
17175   hStVsPlOptXTalk1->GetXaxis()->CenterTitle();
17176   hStVsPlOptXTalk1->GetYaxis()->SetTitle("Strip");
17177   hStVsPlOptXTalk1->GetYaxis()->CenterTitle();
17178   hStVsPlOptXTalk1->SetFillColor(0);
17179   //hStVsPlOptXTalk1->SetMaximum(15000);
17180 
17181   fS="Strip Vs Plane DarkNoise Map SE1";
17182   TH2F* hStVsPlDarkNoise1=new TH2F(fS.c_str(),fS.c_str(),
17183                                            64,-2,62,30,-3,27);
17184   hStVsPlDarkNoise1->GetXaxis()->SetTitle("Plane");
17185   hStVsPlDarkNoise1->GetXaxis()->CenterTitle();
17186   hStVsPlDarkNoise1->GetYaxis()->SetTitle("Strip");
17187   hStVsPlDarkNoise1->GetYaxis()->CenterTitle();
17188   hStVsPlDarkNoise1->SetFillColor(0);
17189   //hStVsPlDarkNoise1->SetMaximum(15000);
17190 
17191   fS="Strip Vs Plane FibreLight Map SE2";
17192   TH2F* hStVsPlFibreLight2=new TH2F(fS.c_str(),fS.c_str(),
17193                                            64,-2,62,30,-3,27);
17194   hStVsPlFibreLight2->GetXaxis()->SetTitle("Plane");
17195   hStVsPlFibreLight2->GetXaxis()->CenterTitle();
17196   hStVsPlFibreLight2->GetYaxis()->SetTitle("Strip");
17197   hStVsPlFibreLight2->GetYaxis()->CenterTitle();
17198   hStVsPlFibreLight2->SetFillColor(0);
17199   //hStVsPlFibreLight2->SetMaximum(15000);
17200 
17201   fS="Strip Vs Plane OpticalXTalk Map SE2";
17202   TH2F* hStVsPlOptXTalk2=new TH2F("hStVsPlOptXTalk2",fS.c_str(),
17203                                            64,-2,62,30,-3,27);
17204   hStVsPlOptXTalk2->GetXaxis()->SetTitle("Plane");
17205   hStVsPlOptXTalk2->GetXaxis()->CenterTitle();
17206   hStVsPlOptXTalk2->GetYaxis()->SetTitle("Strip");
17207   hStVsPlOptXTalk2->GetYaxis()->CenterTitle();
17208   hStVsPlOptXTalk2->SetFillColor(0);
17209   //hStVsPlOptXTalk2->SetMaximum(15000);
17210 
17211   fS="Strip Vs Plane OpticalXTalk on Shared Pmt Map";
17212   TH2F* hStVsPlOptXTalkShared=new TH2F(fS.c_str(),fS.c_str(),
17213                                            64,-2,62,30,-3,27);
17214   hStVsPlOptXTalkShared->GetXaxis()->SetTitle("Plane");
17215   hStVsPlOptXTalkShared->GetXaxis()->CenterTitle();
17216   hStVsPlOptXTalkShared->GetYaxis()->SetTitle("Strip");
17217   hStVsPlOptXTalkShared->GetYaxis()->CenterTitle();
17218   hStVsPlOptXTalkShared->SetFillColor(0);
17219   //hStVsPlOptXTalkShared->SetMaximum(15000);
17220 
17221   fS="Strip Vs Plane OpticalXTalk on Non-Shared Pmt Map";
17222   TH2F* hStVsPlOptXTalkNonShared=new TH2F(fS.c_str(),fS.c_str(),
17223                                            64,-2,62,30,-3,27);
17224   hStVsPlOptXTalkNonShared->GetXaxis()->SetTitle("Plane");
17225   hStVsPlOptXTalkNonShared->GetXaxis()->CenterTitle();
17226   hStVsPlOptXTalkNonShared->GetYaxis()->SetTitle("Strip");
17227   hStVsPlOptXTalkNonShared->GetYaxis()->CenterTitle();
17228   hStVsPlOptXTalkNonShared->SetFillColor(0);
17229   //hStVsPlOptXTalkNonShared->SetMaximum(15000);
17230 
17231   fS="Strip Vs Plane DarkNoise Map SE2";
17232   TH2F* hStVsPlDarkNoise2=new TH2F(fS.c_str(),fS.c_str(),
17233                                            64,-2,62,30,-3,27);
17234   hStVsPlDarkNoise2->GetXaxis()->SetTitle("Plane");
17235   hStVsPlDarkNoise2->GetXaxis()->CenterTitle();
17236   hStVsPlDarkNoise2->GetYaxis()->SetTitle("Strip");
17237   hStVsPlDarkNoise2->GetYaxis()->CenterTitle();
17238   hStVsPlDarkNoise2->SetFillColor(0);
17239   //hStVsPlDarkNoise2->SetMaximum(15000);
17240 
17244   
17245   this->InitialiseLoopVariables();  
17246   
17247   for(Int_t event=0;event<fEvents;event++){
17248     
17249     this->SetLoopVariables(event);
17250 
17251     if (!fTruthHitInfo) break;
17252     TClonesArray &cTruth = *fTruthHitInfo;
17253     Int_t numTruthHits=fTruthHitInfo->GetEntries();
17254     
17255     MSG("CDAnalysis",Msg::kDebug)
17256       <<"Event="<<event
17257       <<", truthHits="<<numTruthHits<<endl;
17258 
17260     //loop over the truth hits
17262     for (Int_t hit=0;hit<numTruthHits;hit++){
17263       //cast the tclonesarray up to a truthhitinfo object
17264       CDTruthHitInfo *hitInfo=
17265         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
17266       
17267       Int_t plane=hitInfo->GetPlane();
17268       Int_t strip=hitInfo->GetStrip();
17269       Int_t mainParticle=hitInfo->GetMainParticle();
17270       Double_t totalEnDep=hitInfo->GetTotalEnDep();
17271       Double_t mainPartEn=hitInfo->GetMainPartEn();
17272       Double_t mainPathLength=hitInfo->GetMainPathLength();
17273       Int_t pmtTruth1=hitInfo->GetPmtTruth1();
17274       Int_t pmtTruth2=hitInfo->GetPmtTruth2();
17275       Int_t vaChip1=hitInfo->GetVaChip1();
17276       Int_t vaChip2=hitInfo->GetVaChip2();
17277 
17278       //if (plane==0) continue;
17279 
17280       hPlane->Fill(plane);
17281       hStrip->Fill(strip);
17282       hMainParticle->Fill(mainParticle);
17283       hTotalEnDep->Fill(totalEnDep);
17284       hMainPartEn->Fill(mainPartEn);
17285       hMainPathLength->Fill(mainPathLength);
17286       hPmtTruth1->Fill(pmtTruth1);
17287       hPmtTruth2->Fill(pmtTruth2);
17288       hVaChip1->Fill(vaChip1);
17289       hVaChip2->Fill(vaChip2);
17290 
17291       //do stripend 1
17292       if (pmtTruth1 & DigiSignal::kFibreLight){
17293         hStVsPlFibreLight1->Fill(plane,strip,1);
17294       }
17295 
17296       if (pmtTruth1 & DigiSignal::kCrosstalkOptical){
17297         hStVsPlOptXTalk1->Fill(plane,strip,1);
17298 
17299         //fill the shared and nonshared
17300         if (vaChip1==1) hStVsPlOptXTalkShared->Fill(plane,strip,1);
17301         else hStVsPlOptXTalkNonShared->Fill(plane,strip,1);
17302       }
17303 
17304       if (pmtTruth1 & DigiSignal::kDarkNoise){
17305         hStVsPlDarkNoise1->Fill(plane,strip,1);
17306       }
17307 
17308       //now do stripend 2
17309       if (pmtTruth2 & DigiSignal::kFibreLight){
17310         hStVsPlFibreLight2->Fill(plane,strip,1);
17311       }
17312 
17313       if (pmtTruth2 & DigiSignal::kCrosstalkOptical){
17314         hStVsPlOptXTalk2->Fill(plane,strip,1);
17315       }
17316 
17317       if (pmtTruth2 & DigiSignal::kDarkNoise){
17318         hStVsPlDarkNoise2->Fill(plane,strip,1);
17319       }
17320 
17321       pStVsPlEnDep->Fill(plane,strip,totalEnDep);
17322       hStVsPlNum->Fill(plane,strip,1);
17323     }
17324     
17325   }//end of for                                       
17326   
17330 
17331   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
17332 
17333   TCanvas *cGeom=new TCanvas("cGeom","Geom",0,0,1200,800);
17334   cGeom->SetFillColor(0);
17335   cGeom->Divide(2,2);
17336   cGeom->cd(1);
17337   hPlane->Draw();
17338   cGeom->cd(2);
17339   hStrip->Draw();
17340   cGeom->cd(3);
17341   hVaChip1->Draw();
17342   cGeom->cd(4);
17343   hVaChip2->Draw();
17344 
17345   TCanvas *cMainParticle=new TCanvas("cMainParticle","MainParticle",0,0,1200,800);
17346   cMainParticle->SetFillColor(0);
17347   cMainParticle->Divide(2,2);
17348   cMainParticle->cd(1);
17349   hMainParticle->Draw();
17350   cMainParticle->cd(2);
17351   hTotalEnDep->Draw();
17352   cMainParticle->cd(3);
17353   hMainPartEn->Draw();
17354   cMainParticle->cd(4);
17355   hPmtTruth1->Draw();
17356   hPmtTruth2->SetLineColor(2);
17357   hPmtTruth2->Draw("same");
17358 
17359   TCanvas *cStVsPlEnDep=new TCanvas("cStVsPlEnDep","StVsPlEnDep",
17360                                     0,0,1200,800);
17361   cStVsPlEnDep->SetFillColor(0);
17362   pStVsPlEnDep->Draw("colz");
17363 
17364   TCanvas *cStVsPlNum=new TCanvas("cStVsPlNum","StVsPlNum",
17365                                   0,0,1200,800);
17366   cStVsPlNum->SetFillColor(0);
17367   hStVsPlNum->Draw("colz");
17368 
17369   TCanvas *cStVsPlFibreLight=new TCanvas("cStVsPlFibreLight",
17370                                          "StVsPlFibreLight",
17371                                          0,0,1200,800);
17372   cStVsPlFibreLight->SetFillColor(0);
17373   cStVsPlFibreLight->Divide(1,2);
17374   cStVsPlFibreLight->cd(1);
17375   hStVsPlFibreLight1->Draw("colz");
17376   cStVsPlFibreLight->cd(2);
17377   hStVsPlFibreLight2->Draw("colz");
17378   
17379   TCanvas *cStVsPlOptXTalk=new TCanvas("cStVsPlOptXTalk",
17380                                          "StVsPlOptXTalk",
17381                                          0,0,1200,800);
17382   cStVsPlOptXTalk->SetFillColor(0);
17383 
17384   cStVsPlOptXTalk->Divide(1,2);
17385   cStVsPlOptXTalk->cd(1);
17386   hStVsPlOptXTalk1->Draw("colz");
17387   cStVsPlOptXTalk->cd(2);
17388   hStVsPlOptXTalk2->Draw("colz");
17389 
17390   TCanvas *cStVsPlOptXTalk2=new TCanvas("cStVsPlOptXTalk2",
17391                                          "StVsPlOptXTalk2",
17392                                          0,0,1200,800);
17393   cStVsPlOptXTalk2->SetFillColor(0);
17394 
17395   cStVsPlOptXTalk2->Divide(1,2);
17396   cStVsPlOptXTalk2->cd(1);
17397   hStVsPlOptXTalkShared->Draw("colz");
17398   cStVsPlOptXTalk2->cd(2);
17399   hStVsPlOptXTalkNonShared->Draw("colz");
17400 
17401   TCanvas *cStVsPlDarkNoise=new TCanvas("cStVsPlDarkNoise",
17402                                          "StVsPlDarkNoise",
17403                                          0,0,1200,800);
17404   cStVsPlDarkNoise->SetFillColor(0);
17405   cStVsPlDarkNoise->Divide(1,2);
17406   cStVsPlDarkNoise->cd(1);
17407   hStVsPlDarkNoise1->Draw("colz");
17408   cStVsPlDarkNoise->cd(2);
17409   hStVsPlDarkNoise2->Draw("colz");
17410 
17411   MSG("CDAnalysis",Msg::kInfo) 
17412     <<" ** Finished TruthAnalysis method **"<<endl;
17413 }
17414 
17415 //......................................................................
17416 
17417 void CDAnalysis::TruthEnDep()
17418 {
17419   MSG("CDAnalysis",Msg::kInfo) 
17420     <<" ** Running TruthEnDep method... **"<<endl;
17421   
17422   //open the output file for the histograms
17423   fOutFile=this->OpenFile(fRunNumber,"TruthEnDep");
17424 
17425   TH1F *hPl20=new TH1F("hPl20","hPl20",200,-1,10);
17426   hPl20->SetTitle("Energy Deposition in plane 20");
17427   hPl20->GetXaxis()->SetTitle("MeV");
17428   hPl20->GetXaxis()->CenterTitle();
17429   hPl20->GetYaxis()->SetTitle("");
17430   hPl20->GetYaxis()->CenterTitle();
17431   hPl20->SetFillColor(0);
17432   hPl20->SetBit(TH1::kCanRebin);
17433 
17434   TH1F *hPl20Mu=new TH1F("hPl20Mu","hPl20Mu",200,-1,10);
17435   hPl20Mu->SetTitle("Energy Deposition in plane 20");
17436   hPl20Mu->GetXaxis()->SetTitle("MeV");
17437   hPl20Mu->GetXaxis()->CenterTitle();
17438   hPl20Mu->GetYaxis()->SetTitle("");
17439   hPl20Mu->GetYaxis()->CenterTitle();
17440   hPl20Mu->SetFillColor(0);
17441   hPl20Mu->SetLineColor(2);
17442   hPl20Mu->SetBit(TH1::kCanRebin);
17443 
17444   TH1F *hPl20NotMu=new TH1F("hPl20NotMu","hPl20NotMu",200,-1,10);
17445   hPl20NotMu->SetTitle("Energy Deposition in plane 20");
17446   hPl20NotMu->GetXaxis()->SetTitle("MeV");
17447   hPl20NotMu->GetXaxis()->CenterTitle();
17448   hPl20NotMu->GetYaxis()->SetTitle("");
17449   hPl20NotMu->GetYaxis()->CenterTitle();
17450   hPl20NotMu->SetFillColor(0);
17451   hPl20NotMu->SetLineColor(3);
17452   hPl20NotMu->SetBit(TH1::kCanRebin);
17453 
17454   TH1F *hSum15_18All=new TH1F("hSum15_18All","hSum15_18All",1000,-2,75);
17455   hSum15_18All->SetTitle("Energy Deposition in 15_18 Track Window");
17456   hSum15_18All->GetXaxis()->SetTitle("MeV");
17457   hSum15_18All->GetXaxis()->CenterTitle();
17458   hSum15_18All->GetYaxis()->SetTitle("");
17459   hSum15_18All->GetYaxis()->CenterTitle();
17460   hSum15_18All->SetFillColor(0);
17461   hSum15_18All->SetBit(TH1::kCanRebin);
17462 
17463   TH1F *hSum15_18Cut=new TH1F("hSum15_18Cut","hSum15_18Cut",500,-1,10);
17464   hSum15_18Cut->SetTitle
17465     ("Energy Deposition per MEU (Cuts on Track Quality)");
17466   hSum15_18Cut->GetXaxis()->SetTitle("MeV");
17467   hSum15_18Cut->GetXaxis()->CenterTitle();
17468   hSum15_18Cut->GetYaxis()->SetTitle("");
17469   hSum15_18Cut->GetYaxis()->CenterTitle();
17470   hSum15_18Cut->SetFillColor(0);
17471   hSum15_18Cut->SetBit(TH1::kCanRebin);
17472 
17473   TH1F *hSum15_18=new TH1F("hSum15_18","hSum15_18",500,-1,10);
17474   hSum15_18->SetTitle("Energy Deposition per MEU");
17475   hSum15_18->GetXaxis()->SetTitle("MeV");
17476   hSum15_18->GetXaxis()->CenterTitle();
17477   hSum15_18->GetYaxis()->SetTitle("");
17478   hSum15_18->GetYaxis()->CenterTitle();
17479   hSum15_18->SetFillColor(0);
17480   hSum15_18->SetBit(TH1::kCanRebin);
17481 
17482   TH1F *hSum15_18Truth=new TH1F("hSum15_18Truth","hSum15_18Truth",
17483                                 500,-1,10);
17484   hSum15_18Truth->SetTitle("Energy Deposition per MEU (True Track)");
17485   hSum15_18Truth->GetXaxis()->SetTitle("MeV");
17486   hSum15_18Truth->GetXaxis()->CenterTitle();
17487   hSum15_18Truth->GetYaxis()->SetTitle("");
17488   hSum15_18Truth->GetYaxis()->CenterTitle();
17489   hSum15_18Truth->SetFillColor(0);
17490   hSum15_18Truth->SetBit(TH1::kCanRebin);
17491 
17492   TH1F *hSumEnDep=new TH1F("hSumEnDep","hSumEnDep",
17493                              2000,-5./1000,50./1000);
17494   hSumEnDep->GetXaxis()->SetTitle("Sum of Energy Dep. in Whole Event");
17495   hSumEnDep->GetXaxis()->SetTitle("SumEnDep");
17496   hSumEnDep->GetXaxis()->CenterTitle();
17497   hSumEnDep->GetYaxis()->SetTitle("");
17498   hSumEnDep->GetYaxis()->CenterTitle();
17499   hSumEnDep->SetFillColor(0);
17500   hSumEnDep->SetBit(TH1::kCanRebin);
17501 
17502   TH1F *hSumEnDepLateT1=new TH1F("hSumEnDepLateT1","hSumEnDepLateT1",
17503                              2000,-5./1000,50./1000);
17504   hSumEnDepLateT1->GetXaxis()->SetTitle("SumEnDep");
17505   hSumEnDepLateT1->GetXaxis()->CenterTitle();
17506   hSumEnDepLateT1->GetYaxis()->SetTitle("");
17507   hSumEnDepLateT1->GetYaxis()->CenterTitle();
17508   hSumEnDepLateT1->SetFillColor(0);
17509   hSumEnDepLateT1->SetBit(TH1::kCanRebin);
17510 
17511   TH1F *hSumEnDepLateT1Cut=new TH1F("hSumEnDepLateT1Cut",
17512                                     "hSumEnDepLateT1Cut",
17513                                     2000,-5./1000,50./1000);
17514   hSumEnDepLateT1Cut->GetXaxis()->SetTitle("SumEnDep");
17515   hSumEnDepLateT1Cut->GetXaxis()->CenterTitle();
17516   hSumEnDepLateT1Cut->GetYaxis()->SetTitle("");
17517   hSumEnDepLateT1Cut->GetYaxis()->CenterTitle();
17518   hSumEnDepLateT1Cut->SetFillColor(0);
17519   hSumEnDepLateT1Cut->SetBit(TH1::kCanRebin);
17520 
17521   TH1F *hSumEnDepLateT2=new TH1F("hSumEnDepLateT2","hSumEnDepLateT2",
17522                              2000,-5./1000,50./1000);
17523   hSumEnDepLateT2->GetXaxis()->SetTitle("SumEnDep");
17524   hSumEnDepLateT2->GetXaxis()->CenterTitle();
17525   hSumEnDepLateT2->GetYaxis()->SetTitle("");
17526   hSumEnDepLateT2->GetYaxis()->CenterTitle();
17527   hSumEnDepLateT2->SetFillColor(0);
17528   hSumEnDepLateT2->SetBit(TH1::kCanRebin);
17529 
17530   TH1F *hRatioScToBeam=new TH1F("hRatioScToBeam","hRatioScToBeam",
17531                                 500,-5./1000,100./1000);
17532   hRatioScToBeam->GetXaxis()->SetTitle("Esc/Ebeam");
17533   hRatioScToBeam->GetXaxis()->CenterTitle();
17534   hRatioScToBeam->GetYaxis()->SetTitle("");
17535   hRatioScToBeam->GetYaxis()->CenterTitle();
17536   hRatioScToBeam->SetFillColor(0);
17537   hRatioScToBeam->SetBit(TH1::kCanRebin);
17538 
17539   TH1F *hRatioScToBeamCut=new TH1F("hRatioScToBeamCut",
17540                                    "hRatioScToBeamCut",
17541                                    500,-5./1000,100./1000);
17542   hRatioScToBeamCut->GetXaxis()->SetTitle("Esc/Ebeam");
17543   hRatioScToBeamCut->GetXaxis()->CenterTitle();
17544   hRatioScToBeamCut->GetYaxis()->SetTitle("");
17545   hRatioScToBeamCut->GetYaxis()->CenterTitle();
17546   hRatioScToBeamCut->SetFillColor(0);
17547   hRatioScToBeamCut->SetBit(TH1::kCanRebin);
17548 
17549   TH1F *hTotalEnDep=new TH1F("hTotalEnDep","hTotalEnDep",
17550                              2000,-5./1000,50./1000);
17551   hTotalEnDep->GetXaxis()->SetTitle("TotalEnDep");
17552   hTotalEnDep->GetXaxis()->CenterTitle();
17553   hTotalEnDep->GetYaxis()->SetTitle("");
17554   hTotalEnDep->GetYaxis()->CenterTitle();
17555   hTotalEnDep->SetFillColor(0);
17556   hTotalEnDep->SetBit(TH1::kCanRebin);
17557 
17558   TH1F *hTotalEnDepMu=new TH1F("hTotalEnDepMu","hTotalEnDepMu",
17559                              2000,-5./1000,50./1000);
17560   hTotalEnDepMu->GetXaxis()->SetTitle("TotalEnDep");
17561   hTotalEnDepMu->GetXaxis()->CenterTitle();
17562   hTotalEnDepMu->GetYaxis()->SetTitle("");
17563   hTotalEnDepMu->GetYaxis()->CenterTitle();
17564   hTotalEnDepMu->SetFillColor(0);
17565   hTotalEnDepMu->SetBit(TH1::kCanRebin);
17566 
17567   TH1F *hTotalEnDep2=new TH1F("hTotalEnDep2","hTotalEnDep2",
17568                              2000,-5./1000,50./1000);
17569   hTotalEnDep2->GetXaxis()->SetTitle("TotalEnDep");
17570   hTotalEnDep2->GetXaxis()->CenterTitle();
17571   hTotalEnDep2->GetYaxis()->SetTitle("");
17572   hTotalEnDep2->GetYaxis()->CenterTitle();
17573   hTotalEnDep2->SetFillColor(0);
17574   hTotalEnDep2->SetBit(TH1::kCanRebin);
17575 
17576   TH1F *hTotalEnDep3=new TH1F("hTotalEnDep3","hTotalEnDep3",
17577                              2000,-5./1000,50./1000);
17578   hTotalEnDep3->GetXaxis()->SetTitle("TotalEnDep");
17579   hTotalEnDep3->GetXaxis()->CenterTitle();
17580   hTotalEnDep3->GetYaxis()->SetTitle("");
17581   hTotalEnDep3->GetYaxis()->CenterTitle();
17582   hTotalEnDep3->SetFillColor(0);
17583   hTotalEnDep3->SetBit(TH1::kCanRebin);
17584 
17585   TH1F *hMainPartEn=new TH1F("hMainPartEn","hMainPartEn",1000,-0.5,2);
17586   hMainPartEn->GetXaxis()->SetTitle("MainPartEn");
17587   hMainPartEn->GetXaxis()->CenterTitle();
17588   hMainPartEn->GetYaxis()->SetTitle("");
17589   hMainPartEn->GetYaxis()->CenterTitle();
17590   hMainPartEn->SetFillColor(0);
17591   hMainPartEn->SetBit(TH1::kCanRebin);
17592 
17593   TH1F *hMainPartEn0=new TH1F("hMainPartEn0","hMainPartEn0",500,-0.5,2);
17594   hMainPartEn0->GetXaxis()->SetTitle("MainPartEn0");
17595   hMainPartEn0->GetXaxis()->CenterTitle();
17596   hMainPartEn0->GetYaxis()->SetTitle("");
17597   hMainPartEn0->GetYaxis()->CenterTitle();
17598   hMainPartEn0->SetFillColor(0);
17599   hMainPartEn0->SetBit(TH1::kCanRebin);
17600 
17601   TH1F *hMainPathLength=new TH1F("hMainPathLength","hMainPathLength",
17602                                  500,-0.01,0.1);
17603   hMainPathLength->GetXaxis()->SetTitle("MainPathLength");
17604   hMainPathLength->GetXaxis()->CenterTitle();
17605   hMainPathLength->GetYaxis()->SetTitle("");
17606   hMainPathLength->GetYaxis()->CenterTitle();
17607   hMainPathLength->SetFillColor(0);
17608   hMainPathLength->SetBit(TH1::kCanRebin);
17609 
17610   TH1F *hMainPLInPlane=new TH1F("hMainPLInPlane","hMainPLInPlane",
17611                                 500,-0.01,0.1);
17612   hMainPLInPlane->GetXaxis()->SetTitle("MainPathLength");
17613   hMainPLInPlane->GetXaxis()->CenterTitle();
17614   hMainPLInPlane->GetYaxis()->SetTitle("");
17615   hMainPLInPlane->GetYaxis()->CenterTitle();
17616   hMainPLInPlane->SetFillColor(0);
17617   hMainPLInPlane->SetBit(TH1::kCanRebin);
17618 
17619   fS="Strip Vs Plane EnergyDep Map";
17620   TProfile2D* pStVsPlEnDep=new TProfile2D(fS.c_str(),fS.c_str(),
17621                                            64,-2,62,30,-3,27);
17622   pStVsPlEnDep->GetXaxis()->SetTitle("Plane");
17623   pStVsPlEnDep->GetXaxis()->CenterTitle();
17624   pStVsPlEnDep->GetYaxis()->SetTitle("Strip");
17625   pStVsPlEnDep->GetYaxis()->CenterTitle();
17626   pStVsPlEnDep->SetFillColor(0);
17627   //pStVsPlEnDep->SetMaximum(15000);
17628 
17629   fS="Strip Vs Plane EnergyDepMu Map";
17630   TProfile2D* pStVsPlEnDepMu=new TProfile2D(fS.c_str(),fS.c_str(),
17631                                            64,-2,62,30,-3,27);
17632   pStVsPlEnDepMu->GetXaxis()->SetTitle("Plane");
17633   pStVsPlEnDepMu->GetXaxis()->CenterTitle();
17634   pStVsPlEnDepMu->GetYaxis()->SetTitle("Strip");
17635   pStVsPlEnDepMu->GetYaxis()->CenterTitle();
17636   pStVsPlEnDepMu->SetFillColor(0);
17637   //pStVsPlEnDepMu->SetMaximum(15000);
17638 
17639   fS="Strip Vs Plane EnergyDepNotMu Map";
17640   TProfile2D* pStVsPlEnDepNotMu=new TProfile2D(fS.c_str(),fS.c_str(),
17641                                            64,-2,62,30,-3,27);
17642   pStVsPlEnDepNotMu->GetXaxis()->SetTitle("Plane");
17643   pStVsPlEnDepNotMu->GetXaxis()->CenterTitle();
17644   pStVsPlEnDepNotMu->GetYaxis()->SetTitle("Strip");
17645   pStVsPlEnDepNotMu->GetYaxis()->CenterTitle();
17646   pStVsPlEnDepNotMu->SetFillColor(0);
17647   //pStVsPlEnDepNotMu->SetMaximum(15000);
17648 
17649   fS="Strip Vs Plane EnergyDepNotMuLate Map";
17650   TProfile2D* pStVsPlEnDepNotMuLate=new TProfile2D(fS.c_str(),fS.c_str(),
17651                                            64,-2,62,30,-3,27);
17652   pStVsPlEnDepNotMuLate->GetXaxis()->SetTitle("Plane");
17653   pStVsPlEnDepNotMuLate->GetXaxis()->CenterTitle();
17654   pStVsPlEnDepNotMuLate->GetYaxis()->SetTitle("Strip");
17655   pStVsPlEnDepNotMuLate->GetYaxis()->CenterTitle();
17656   pStVsPlEnDepNotMuLate->SetFillColor(0);
17657   //pStVsPlEnDepNotMuLate->SetMaximum(15000);
17658 
17659   fS="Strip Vs Plane Num Hits Map";
17660   TH2F* hStVsPlNum=new TH2F(fS.c_str(),fS.c_str(),64,-2,62,30,-3,27);
17661   hStVsPlNum->GetXaxis()->SetTitle("Plane");
17662   hStVsPlNum->GetXaxis()->CenterTitle();
17663   hStVsPlNum->GetYaxis()->SetTitle("Strip");
17664   hStVsPlNum->GetYaxis()->CenterTitle();
17665   hStVsPlNum->SetFillColor(0);
17666   //hStVsPlNum->SetMaximum(15000);
17667 
17668   fS="Strip Vs Plane NumMu Hits Map";
17669   TH2F* hStVsPlNumMu=new TH2F(fS.c_str(),fS.c_str(),64,-2,62,30,-3,27);
17670   hStVsPlNumMu->GetXaxis()->SetTitle("Plane");
17671   hStVsPlNumMu->GetXaxis()->CenterTitle();
17672   hStVsPlNumMu->GetYaxis()->SetTitle("Strip");
17673   hStVsPlNumMu->GetYaxis()->CenterTitle();
17674   hStVsPlNumMu->SetFillColor(0);
17675   //hStVsPlNumMu->SetMaximum(15000);
17676 
17677   fS="Strip Vs Plane NumNotMu Hits Map";
17678   TH2F* hStVsPlNumNotMu=new TH2F(fS.c_str(),fS.c_str(),
17679                                  64,-2,62,30,-3,27);
17680   hStVsPlNumNotMu->GetXaxis()->SetTitle("Plane");
17681   hStVsPlNumNotMu->GetXaxis()->CenterTitle();
17682   hStVsPlNumNotMu->GetYaxis()->SetTitle("Strip");
17683   hStVsPlNumNotMu->GetYaxis()->CenterTitle();
17684   hStVsPlNumNotMu->SetFillColor(0);
17685   //hStVsPlNumNotMu->SetMaximum(15000);
17686 
17687   fS="Strip Vs Plane NumNotMuLate Hits Map";
17688   TH2F* hStVsPlNumNotMuLate=new TH2F(fS.c_str(),fS.c_str(),
17689                                  64,-2,62,30,-3,27);
17690   hStVsPlNumNotMuLate->GetXaxis()->SetTitle("Plane");
17691   hStVsPlNumNotMuLate->GetXaxis()->CenterTitle();
17692   hStVsPlNumNotMuLate->GetYaxis()->SetTitle("Strip");
17693   hStVsPlNumNotMuLate->GetYaxis()->CenterTitle();
17694   hStVsPlNumNotMuLate->SetFillColor(0);
17695   //hStVsPlNumNotMuLate->SetMaximum(15000);
17696 
17697   fS="Path Length Vs EnDep";
17698   TH2F* hPathLenVsEnDep=new TH2F(fS.c_str(),fS.c_str(),
17699                                  500,-1./1000,10./1000,
17700                                  500,-0.005,0.04);
17701   hPathLenVsEnDep->GetXaxis()->SetTitle("EnDep");
17702   hPathLenVsEnDep->GetXaxis()->CenterTitle();
17703   hPathLenVsEnDep->GetYaxis()->SetTitle("Path Length");
17704   hPathLenVsEnDep->GetYaxis()->CenterTitle();
17705   hPathLenVsEnDep->SetFillColor(0);
17706   //hPathLenVsEnDep->SetMaximum(15000);
17707 
17708   fS="EnDep Vs Plane";
17709   TProfile* pEnDepVsPl=new TProfile(fS.c_str(),fS.c_str(),66,-4,62);
17710   pEnDepVsPl->GetXaxis()->SetTitle("Plane");
17711   pEnDepVsPl->GetXaxis()->CenterTitle();
17712   pEnDepVsPl->GetYaxis()->SetTitle("EnDep");
17713   pEnDepVsPl->GetYaxis()->CenterTitle();
17714   pEnDepVsPl->SetFillColor(0);
17715   //pEnDepVsPl->SetMaximum(15000);
17716 
17717   fS="MainParticle Energy Vs Plane";
17718   TProfile* pEnVsPl=new TProfile(fS.c_str(),fS.c_str(),66,-4,62);
17719   pEnVsPl->GetXaxis()->SetTitle("Plane");
17720   pEnVsPl->GetXaxis()->CenterTitle();
17721   pEnVsPl->GetYaxis()->SetTitle("MainParticle Energy");
17722   pEnVsPl->GetYaxis()->CenterTitle();
17723   pEnVsPl->SetFillColor(0);
17724   //pEnVsPl->SetMaximum(15000);
17725 
17726   fS="Esc/Ebeam Vs Last Plane";
17727   TProfile* pEscEbeamVsLastPl=new TProfile("pEscEbeamVsLastPl",
17728                                            fS.c_str(),66,-4,62);
17729   pEscEbeamVsLastPl->GetXaxis()->SetTitle("Last Plane");
17730   pEscEbeamVsLastPl->GetXaxis()->CenterTitle();
17731   pEscEbeamVsLastPl->GetYaxis()->SetTitle("Esc/Ebeam");
17732   pEscEbeamVsLastPl->GetYaxis()->CenterTitle();
17733   pEscEbeamVsLastPl->SetFillColor(0);
17734   //pEscEbeamVsLastPl->SetMaximum(15000);
17735 
17736   fS="Esc/Ebeam Vs First Plane Included";
17737   TProfile* pEscEbeamVsFirstPl=new TProfile("pEscEbeamVsFirstPl",
17738                                             fS.c_str(),66,-4,62);
17739   pEscEbeamVsFirstPl->GetXaxis()->SetTitle("First Plane Included");
17740   pEscEbeamVsFirstPl->GetXaxis()->CenterTitle();
17741   pEscEbeamVsFirstPl->GetYaxis()->SetTitle("Esc/Ebeam");
17742   pEscEbeamVsFirstPl->GetYaxis()->CenterTitle();
17743   pEscEbeamVsFirstPl->SetFillColor(0);
17744   //pEscEbeamVsFirstPl->SetMaximum(15000);
17745 
17746   Int_t straightCutCounter=0;
17747   Double_t simple15_18=0;
17748   Int_t simple15_18Counter=0;
17749 
17753   
17754   this->InitialiseLoopVariables();  
17755   
17756   for(Int_t event=0;event<fEvents;event++){
17757     
17758     this->SetLoopVariables(event);
17759 
17760     if (!fTruthHitInfo) break;
17761     TClonesArray &cTruth = *fTruthHitInfo;
17762     Int_t numTruthHits=fTruthHitInfo->GetEntries();
17763     
17764     MSG("CDAnalysis",Msg::kDebug)
17765       <<"Event="<<event
17766       <<", truthHits="<<numTruthHits<<endl;
17767 
17768     //cut on not straight tracks
17769     Double_t mainX1Cut=0.5;
17770     if (!this->IsStraightTrack(mainX1Cut)){
17771       straightCutCounter++;
17772       continue;
17773     }
17774 
17775     //calc and set fLastPlane
17776     this->CalcLastPlaneOnTrk();
17777     Int_t lastPlaneTruth=this->CalcLastPlaneTruth();
17778 
17779     //make event length cuts
17780     Bool_t goodEvLen=!(this->CutOnEventLength());
17781     //make track quality cuts
17782     //Bool_t goodTrackQuality=!(this->CutOnTrackQuality());
17783     //make sure that the first plane makes sense and was actually set
17784     Bool_t goodFirstPlane=true;
17785     if (fFirstPlane<0 || fFirstPlane>59) goodFirstPlane=false;
17786 
17787     Double_t partEn=-1;
17788     Double_t sumScEnDep=0;
17789     Double_t sumScEnDepCut=0;
17790     Double_t sumScEnDepLateT1=0;
17791     Double_t sumScEnDepLateT1Cut=0;
17792     Double_t sumScEnDepLateT2=0;
17793     Double_t sum15_18=0;
17794     Double_t sum15_18Truth=0;
17795     Double_t sum15_18Cut=0;
17796     Double_t simple15_18Local=0;
17797 
17798     for (Int_t pl=0;pl<=fLastPlane;pl++){
17799       Double_t mainPL=this->TrueMainPL(pl,event);
17800       hMainPLInPlane->Fill(mainPL);
17801     }
17802 
17804     //loop over the truth hits
17806     for (Int_t hit=0;hit<numTruthHits;hit++){
17807       //cast the tclonesarray up to a truthhitinfo object
17808       CDTruthHitInfo *hitInfo=
17809         dynamic_cast<CDTruthHitInfo*>(cTruth[hit]);
17810       
17811       Int_t plane=hitInfo->GetPlane();
17812       Int_t strip=hitInfo->GetStrip();
17813       Double_t totalEnDep=hitInfo->GetTotalEnDep();
17814       Double_t mainPartEn=hitInfo->GetMainPartEn();
17815       Double_t mainPathLength=hitInfo->GetMainPathLength();
17816       Double_t earliestT1=hitInfo->GetEarliestT1();
17817       Double_t latestT2=hitInfo->GetLatestT2();
17818       Int_t pmtTruth1=hitInfo->GetPmtTruth1();
17819       Int_t pmtTruth2=hitInfo->GetPmtTruth2();
17820       Int_t mainParticle=hitInfo->GetMainParticle();
17821 
17822       Int_t muon=13;
17823 
17824       if (totalEnDep==0) continue;
17825 
17826       //do simple window calc of 15 planes 29-15+1=15
17827       if (plane>=15 && plane<=29) simple15_18Local+=1000*totalEnDep;
17828 
17829       //get the largest particle energy
17830       if (mainPartEn>partEn) partEn=mainPartEn;
17831       if (fRunNumber==60002) partEn=1.8;
17832 
17833       //sum the energy deposition for every strip
17834       sumScEnDep+=totalEnDep;
17835       //sum the energy deposition for tracks passing "data" cuts
17836       if (goodEvLen && goodFirstPlane){
17837         sumScEnDepCut+=totalEnDep;
17838       }
17839 
17840       //sum the energy in the 15_18 window on the track
17841       //if lp=48 then >15  and <=30 then have 15 planes in total
17842       //make sure that there are actually 15 planes to add up
17843       if (fLastPlane>18+15 &&
17844           plane>fLastPlane-18-15 && plane<=fLastPlane-18){
17845         sum15_18+=1000*totalEnDep;
17846       }
17847       //sum the energy for the true end of track
17848       if (lastPlaneTruth>18+15 && 
17849           plane>lastPlaneTruth-18-15 && plane<=lastPlaneTruth-18){
17850         sum15_18Truth+=1000*totalEnDep;
17851       }     
17852       //sum the energy for the tracks that pass data selection cuts
17853       if (goodEvLen && goodFirstPlane &&
17854           plane>lastPlaneTruth-18-15 && plane<=lastPlaneTruth-18){
17855         sum15_18Cut+=1000*totalEnDep;
17856       }
17857       
17858 
17859       if (plane==0) {
17860         if (abs(mainParticle)==muon) hMainPartEn0->Fill(mainPartEn);
17861         if (mainPartEn==0){
17862           MSG("CDAnalysis",Msg::kInfo)
17863             <<"mainPart="<<mainParticle
17864             <<", mainPL="<<mainPathLength
17865             <<", truth1="<<pmtTruth1
17866             <<", truth2="<<pmtTruth2<<endl;
17867         }
17868       }
17869 
17870       hTotalEnDep->Fill(totalEnDep);
17871       hMainPartEn->Fill(mainPartEn);
17872       hMainPathLength->Fill(mainPathLength);
17873 
17874       pStVsPlEnDep->Fill(plane,strip,totalEnDep);
17875       hStVsPlNum->Fill(plane,strip,1);
17876       if (mainParticle==muon){
17877         hPathLenVsEnDep->Fill(totalEnDep,mainPathLength,1);
17878 
17879         hTotalEnDepMu->Fill(totalEnDep);
17880         pStVsPlEnDepMu->Fill(plane,strip,totalEnDep);
17881         hStVsPlNumMu->Fill(plane,strip,1);
17882       }
17883       if (mainParticle!=muon){
17884         hTotalEnDep2->Fill(totalEnDep);
17885         pStVsPlEnDepNotMu->Fill(plane,strip,totalEnDep);
17886         hStVsPlNumNotMu->Fill(plane,strip,1);
17887 
17888         //fill the late histos
17889         if (earliestT1>15e-9){
17890           hTotalEnDep3->Fill(totalEnDep);
17891           pStVsPlEnDepNotMuLate->Fill(plane,strip,totalEnDep);
17892           hStVsPlNumNotMuLate->Fill(plane,strip,1);
17893 
17894           //sum the energy deposition for every strip
17895           sumScEnDepLateT1+=totalEnDep;
17896         }
17897         if (latestT2>15e-9){
17898           sumScEnDepLateT2+=totalEnDep;
17899         }
17900         if (earliestT1>15e-9 && earliestT1<500e-9){
17901           //sum the energy deposition for every strip
17902           sumScEnDepLateT1Cut+=totalEnDep;
17903         }
17904       }
17905       
17906       //look at a particular plane
17907       if (plane==20){
17908         hPl20->Fill(1000*totalEnDep);
17909         if (mainParticle==muon){
17910           hPl20Mu->Fill(1000*totalEnDep);
17911         }
17912         else{
17913           hPl20NotMu->Fill(1000*totalEnDep);
17914         }
17915       }
17916 
17917       pEnDepVsPl->Fill(plane,totalEnDep);
17918       if (mainParticle==muon) pEnVsPl->Fill(plane,mainPartEn);
17919     }
17921     //end of loop over the truth hits
17923 
17924     //look at dependence of ratio on which planes are included
17925     for (Int_t firstPl=0;firstPl<60;firstPl++){
17926       if (firstPl<fLastPlane){
17927         pEscEbeamVsFirstPl->Fill(firstPl,sumScEnDep/partEn);
17928       }
17929     }
17930 
17931     //do simple window calc
17932     if (simple15_18Local>0){
17933       simple15_18+=simple15_18Local;
17934       simple15_18Counter++;
17935       MAXMSG("CDAnalysis",Msg::kInfo,1)
17936         <<"simple 15_18 local="<<simple15_18Local/15
17937         <<", av="<<(simple15_18/15)/simple15_18Counter
17938         <<" (N="<<simple15_18Counter<<")"<<endl;
17939     }
17940 
17941     //fill the histos
17942     hSumEnDep->Fill(sumScEnDep);
17943     hSumEnDepLateT1->Fill(sumScEnDepLateT1);
17944     hSumEnDepLateT1Cut->Fill(sumScEnDepLateT1Cut);
17945     hSumEnDepLateT2->Fill(sumScEnDepLateT2);
17946     if (partEn) {
17947       hRatioScToBeam->Fill(sumScEnDep/partEn);
17948       //fill the prof
17949       pEscEbeamVsLastPl->Fill(fLastPlane,sumScEnDep/partEn);
17950 
17951       if (sumScEnDepCut>0) hRatioScToBeamCut->
17952                              Fill(sumScEnDepCut/partEn);
17953     }
17954     else MSG("CDAnalysis",Msg::kWarning)<<"partEn="<<partEn<<endl;
17955 
17956     if (sum15_18<10 && sum15_18>0){
17957       MSG("CDAnalysis",Msg::kInfo)
17958         <<"Very low 15_18="<<sum15_18/15<<", event="<<event<<endl;
17959     }
17960     if (sum15_18>0) hSum15_18->Fill(sum15_18/15);
17961     if (sum15_18Cut>0) hSum15_18Cut->Fill(sum15_18Cut/15);
17962     if (sum15_18Truth>0) hSum15_18Truth->Fill(sum15_18Truth/15);
17963     if (sum15_18>0) hSum15_18All->Fill(sum15_18);
17964   }//end of for                                       
17965   
17969 
17970   MSG("CDAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
17971 
17972   MSG("CDAnalysis",Msg::kInfo)
17973     <<"Straight Cut Counter="<<straightCutCounter<<endl;
17974 
17975   TCanvas *cSumEnDep=new TCanvas("cSumEnDep","SumEnDep",
17976                                  0,0,1200,800);
17977   cSumEnDep->SetFillColor(0);
17978   cSumEnDep->Divide(3,3);
17979   cSumEnDep->cd(1);
17980   hRatioScToBeam->Draw();
17981   cSumEnDep->cd(2);
17982   //hSum15_18Cut->Draw();
17983   hRatioScToBeamCut->Draw();
17984   cSumEnDep->cd(3);
17985   hSumEnDep->Draw();
17986   cSumEnDep->cd(4);
17987   hSumEnDepLateT1->Draw();
17988   cSumEnDep->cd(5);
17989   hSumEnDepLateT1Cut->Draw();
17990   cSumEnDep->cd(6);
17991   hSumEnDepLateT2->Draw();
17992   cSumEnDep->cd(7);
17993   hSum15_18All->Draw();
17994   cSumEnDep->cd(8);
17995   hSum15_18->Draw();
17996   cSumEnDep->cd(9);
17997   hSum15_18Truth->Draw();
17998 
17999   TCanvas *cEscEbeam=new TCanvas("cEscEbeam","cEscEbeam",
18000                                  0,0,1200,800);
18001   cEscEbeam->SetFillColor(0);
18002   cEscEbeam->Divide(1,2);
18003   cEscEbeam->cd(1);
18004   pEscEbeamVsLastPl->Draw();
18005   cEscEbeam->cd(2);
18006   pEscEbeamVsFirstPl->Draw();
18007 
18008 
18009 
18010   Double_t enWith500nsCut=hSumEnDep->GetMean()-
18011     hSumEnDepLateT1->GetMean()+
18012     hSumEnDepLateT1Cut->GetMean();
18013 
18014   Double_t partEn=1;
18015   if (fMainParticleEnergy>1.7 && fMainParticleEnergy<1.9) partEn=1.8;
18016   if (fMainParticleEnergy>1.5 && fMainParticleEnergy<1.7) partEn=1.6;
18017   if (fMainParticleEnergy>1.3 && fMainParticleEnergy<1.5) partEn=1.4;
18018   if (fMainParticleEnergy>1.1 && fMainParticleEnergy<1.3) partEn=1.2;
18019   if (fMainParticleEnergy>0.9 && fMainParticleEnergy<1.1) partEn=1.0;
18020 
18021   MSG("CDAnalysis",Msg::kInfo)
18022     <<endl
18023     <<"*** Ratio of Energy in Sc to Steel Section ***"<<endl
18024     <<"totalEn="<<hSumEnDep->GetMean()
18025     <<" +/- "<<hSumEnDep->GetRMS()/sqrt(hSumEnDep->GetEntries())
18026     <<" ("<<100*(hSumEnDep->GetRMS()/sqrt(hSumEnDep->GetEntries()))/
18027     hSumEnDep->GetMean()<<"%)"
18028     <<endl
18029     <<"ratio="<<hSumEnDep->GetMean()/partEn
18030     <<" +/- "<<100*(hSumEnDep->GetRMS()/sqrt(hSumEnDep->GetEntries()))/
18031     hSumEnDep->GetMean()<<"%"
18032     <<endl
18033     <<"lateEn(>15ns)="<<hSumEnDepLateT1->GetMean()<<endl
18034     <<endl
18035     <<"lateT1/total="<<100*hSumEnDepLateT1->GetMean()/
18036     hSumEnDep->GetMean()<<"%"
18037     <<" (ratio="<<hSumEnDepLateT1->GetMean()/partEn<<")"
18038     <<endl
18039     <<"lateT1Cut/total="<<100*hSumEnDepLateT1Cut->GetMean()/
18040     hSumEnDep->GetMean()<<"%"
18041     <<" (ratio="<<hSumEnDepLateT1Cut->GetMean()/partEn<<")"
18042     <<endl
18043     <<"lateT2/total="<<100*hSumEnDepLateT2->GetMean()/
18044     hSumEnDep->GetMean()<<"%"
18045     <<" (ratio="<<hSumEnDepLateT2->GetMean()/partEn<<")"
18046     <<endl
18047     <<endl
18048     <<"enWith500nsCut="<<enWith500nsCut<<endl
18049     <<"fMainParticleEnergy="<<fMainParticleEnergy<<" (using "
18050     <<partEn<<")"<<endl
18051     <<"ratio="<<enWith500nsCut/partEn<<endl
18052     <<"ratio (with track cuts)="<<hRatioScToBeamCut->GetMean()
18053     <<" +/- "<<100*((hRatioScToBeamCut->GetRMS()/
18054                      sqrt(hRatioScToBeamCut->GetEntries()))/
18055                     hRatioScToBeamCut->GetMean())<<"%"
18056     <<endl
18057     <<"*** End of Section ***"<<endl
18058     <<endl;
18059 
18060   MSG("CDAnalysis",Msg::kInfo)
18061     <<endl
18062     <<"*** Energy Loss in Window Section ***"<<endl
18063     <<"15_18="<<hSum15_18->GetMean()
18064     <<" MeV +/- "<<hSum15_18->GetRMS()/sqrt(hSum15_18->GetEntries())
18065     <<" ("<<100*((hSum15_18->GetRMS()/sqrt(hSum15_18->GetEntries()))/
18066                  hSum15_18->GetMean())<<"%)"
18067     <<", N="<<hSum15_18->GetEntries()
18068     <<endl
18069     <<"15_18Truth="<<hSum15_18Truth->GetMean()
18070     <<" MeV +/- "<<(hSum15_18Truth->GetRMS()/
18071                     sqrt(hSum15_18Truth->GetEntries()))
18072     <<" ("<<100*((hSum15_18Truth->GetRMS()/
18073                  sqrt(hSum15_18Truth->GetEntries()))/
18074                  hSum15_18Truth->GetMean())<<"%)"
18075     <<", N="<<hSum15_18Truth->GetEntries()
18076     <<endl
18077     <<"15_18Cut="<<hSum15_18Cut->GetMean()
18078     <<" MeV +/- "<<(hSum15_18Cut->GetRMS()/
18079                     sqrt(hSum15_18Cut->GetEntries()))
18080     <<" ("<<100*((hSum15_18Cut->GetRMS()/
18081                  sqrt(hSum15_18Cut->GetEntries()))/
18082                  hSum15_18Cut->GetMean())<<"%)"
18083     <<", N="<<hSum15_18Cut->GetEntries()
18084     <<endl
18085     <<"*** End of Section ***"<<endl
18086     <<endl;
18087 
18088   TCanvas *cMainParticle=new TCanvas("cMainParticle","MainParticle",
18089                                      0,0,1200,800);
18090   cMainParticle->SetFillColor(0);
18091   cMainParticle->Divide(2,2);
18092   cMainParticle->cd(1);
18093   hMainPartEn0->Draw();
18094   cMainParticle->cd(2);
18095   hTotalEnDep->Draw();
18096   cMainParticle->cd(3);
18097   hMainPartEn->Draw();
18098   cMainParticle->cd(4);
18099   hMainPathLength->Draw();
18100 
18101   TCanvas *cEnDep=new TCanvas("cEnDep","EnDep",
18102                                      0,0,1200,800);
18103   cEnDep->SetFillColor(0);
18104   cEnDep->Divide(2,3);
18105   cEnDep->cd(1);
18106   hTotalEnDep->Draw();
18107   cEnDep->cd(2);
18108   hTotalEnDepMu->Draw();
18109   cEnDep->cd(3);
18110   hTotalEnDep2->Draw();
18111   cEnDep->cd(4);
18112   hTotalEnDep3->Draw();
18113   cEnDep->cd(5);
18114 
18115   cEnDep->cd(6);
18116 
18117 
18118   TCanvas *cStVsPlEnDep=new TCanvas("cStVsPlEnDep","StVsPlEnDep",
18119                                     0,0,1200,800);
18120   cStVsPlEnDep->SetFillColor(0);
18121   pStVsPlEnDep->Draw("colz");
18122 
18123   TCanvas *cStVsPlEnDepMu=new TCanvas("cStVsPlEnDepMu","StVsPlEnDepMu",
18124                                     0,0,1200,800);
18125   cStVsPlEnDepMu->SetFillColor(0);
18126   cStVsPlEnDepMu->Divide(2,2);
18127   cStVsPlEnDepMu->cd(1);
18128   pStVsPlEnDep->Draw("colz");
18129   cStVsPlEnDepMu->cd(2);
18130   pStVsPlEnDepMu->Draw("colz");
18131   cStVsPlEnDepMu->cd(3);
18132   pStVsPlEnDepNotMu->Draw("colz");
18133   cStVsPlEnDepMu->cd(4);
18134   pStVsPlEnDepNotMuLate->Draw("colz");
18135 
18136   TCanvas *cStVsPlNum=new TCanvas("cStVsPlNum","StVsPlNum",
18137                                   0,0,1200,800);
18138   cStVsPlNum->SetFillColor(0);
18139   cStVsPlNum->Divide(2,2);
18140   cStVsPlNum->cd(1);
18141   hStVsPlNum->Draw("colz");
18142   cStVsPlNum->cd(2);
18143   hStVsPlNumMu->Draw("colz");
18144   cStVsPlNum->cd(3);
18145   hStVsPlNumNotMu->Draw("colz");
18146   cStVsPlNum->cd(4);
18147   hStVsPlNumNotMuLate->Draw("colz");
18148 
18149   TCanvas *cEnVsPl=new TCanvas("cEnVsPl","cEnVsPl",0,0,1200,800);
18150   cEnVsPl->SetFillColor(0);
18151   cEnVsPl->Divide(2,2);
18152   cEnVsPl->cd(1);
18153   pEnDepVsPl->Draw();
18154   cEnVsPl->cd(2);
18155   pEnVsPl->Draw();
18156   cEnVsPl->cd(3);
18157   hPl20->Draw();
18158   cEnVsPl->cd(4);
18159   hPl20Mu->Draw();
18160   hPl20NotMu->Draw("sames");
18161 
18162   TCanvas *cPathLenVsEnDep=new TCanvas("cPathLenVsEnDep",
18163                                        "cPathLenVsEnDep",0,0,1200,800);
18164   cPathLenVsEnDep->SetFillColor(0);
18165   //cPathLenVsEnDep->Divide(1,2);
18166   //cPathLenVsEnDep->cd(1);
18167   hPathLenVsEnDep->Draw("colz");
18168 
18169   MSG("CDAnalysis",Msg::kInfo) 
18170     <<" ** Finished TruthEnDep method **"<<endl;
18171 }
18172 
18173 //......................................................................

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