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

ConcatArrays.cxx

Go to the documentation of this file.
00001 
00002 // $Id: ConcatArrays.cxx,v 1.7 2007/01/15 20:16:28 rhatcher Exp $
00003 //
00004 // A series of helper functions (primarily for minossoft MCMerge pkg)
00005 // to concatenate truth and hit-level information stored in TClonesArray
00006 // containers, properly adjusting indices in the input arrays.
00007 //
00008 // K. Arms
00009 // arms@physics.umn.edu
00011 #include <MCMerge/ConcatArrays.h>
00012 
00013 #ifdef EVENT_KINEMATICS_PKGS
00014 #include <EventKinematics/NuEvtKin.h>
00015 #include <EventKinematics/StdHepUtil.h>
00016 using namespace StdHepUtil;
00017 #endif
00018 
00019 #include <Digitization/DigiScintHit.h>
00020 #include <REROOT_Classes/REROOT_StdHep.h>
00021 #include <REROOT_Classes/REROOT_StdHepHead.h>
00022 #include <REROOT_Classes/REROOT_NeuKin.h>
00023 #include <REROOT_Classes/REROOT_FluxInfo.h>
00024 #include <REROOT_Classes/REROOT_FluxWgt.h>
00025 #include "TParticle.h"
00026 #include "TMath.h"
00027 
00028 #include "Riostream.h"
00029 #include "TClass.h"
00030 
00031 //CVSID("$Id: ConcatArrays.cxx,v 1.7 2007/01/15 20:16:28 rhatcher Exp $");
00032 
00033 //__________________________________________________________________________
00034 void ConcatArrays::ConcatDigiScintHits(TClonesArray*  addList,
00035                                        TClonesArray*  permList,
00036                                        Int_t          permStdHepSz) {
00037   // Concatenate (permList += addList)
00038   // --> Call *before* ConcatStdHep
00039 
00040   if (!addList || !permList) return;
00041 
00042   const Int_t oldSize = permList->GetEntriesFast();
00043   const Int_t newSize = oldSize + addList->GetEntriesFast();
00044 
00045   for (Int_t i = oldSize; i < newSize; i++) {
00046     DigiScintHit* tempHit =
00047       dynamic_cast<DigiScintHit*>(addList->At(i-oldSize));
00048 
00049     if (tempHit) {
00050       Int_t oldId = tempHit->TrackId();
00051       Int_t newId = (oldId < 0)? oldId - permStdHepSz : oldId + permStdHepSz ;
00052       tempHit->SetTrackId( newId );
00053 
00054       new( (*permList)[i] ) DigiScintHit( *tempHit );
00055     }
00056   }
00057   
00058 }
00059 //__________________________________________________________________________
00060 void ConcatArrays::ConcatFluxInfo(TClonesArray*  addList,
00061                                   TClonesArray*  permList){
00062   // Concatenate (permList += addList)
00063 
00064   if (!addList || !permList) return;
00065 
00066   const Int_t oldSize = permList->GetEntriesFast();
00067   const Int_t newSize = oldSize + addList->GetEntriesFast();
00068 
00069   for (Int_t i = oldSize; i < newSize; i++)
00070     new( (*permList)[i] ) REROOT_FluxInfo( *dynamic_cast<REROOT_FluxInfo*>(addList->At(i-oldSize)) );
00071 
00072 }
00073 //__________________________________________________________________________
00074 void ConcatArrays::ConcatFluxWgt(TClonesArray*  addList,
00075                                  TClonesArray*  permList){
00076   // Concatenate (permList += addList)
00077 
00078   if (!addList || !permList) return;
00079 
00080   const Int_t oldSize = permList->GetEntriesFast();
00081   const Int_t newSize = oldSize + addList->GetEntriesFast();
00082 
00083   for (Int_t i = oldSize; i < newSize; i++)
00084     new( (*permList)[i] ) REROOT_FluxWgt( *dynamic_cast<REROOT_FluxWgt*>(addList->At(i-oldSize)) );
00085 
00086 }
00087 //__________________________________________________________________________
00088 void ConcatArrays::ConcatNuEvtKin(TClonesArray*  addList,
00089                                   TClonesArray*  permList,
00090                                   TClonesArray*  stdhepList){
00091   // Concatenate (permList += addList)
00092 
00093   if (!addList || !permList || !stdhepList) return;
00094 
00095 #ifdef EVENT_KINEMATICS_PKGS
00096   const Int_t oldSize = permList->GetEntriesFast();
00097   const Int_t newSize = oldSize + addList->GetEntriesFast();
00098 
00099   for (Int_t i = oldSize; i < newSize; i++)
00100     new( (*permList)[i] ) NuEvtKin( *dynamic_cast<NuEvtKin*>(addList->At(i-oldSize)) );
00101 
00102 #endif  
00103 
00104 }
00105 //__________________________________________________________________________
00106 void ConcatArrays::ConcatNuKin(TClonesArray*  addList,
00107                                TClonesArray*  permList){
00108   // Concatenate (permList += addList)
00109 
00110   if (!addList || !permList) return;
00111 
00112   const Int_t oldSize = permList->GetEntriesFast();
00113   const Int_t newSize = oldSize + addList->GetEntriesFast();
00114 
00115   for (Int_t i = oldSize; i < newSize; i++)
00116     new( (*permList)[i] ) REROOT_NeuKin( *dynamic_cast<REROOT_NeuKin*>(addList->At(i-oldSize)) );
00117 
00118 }
00119 //__________________________________________________________________________
00120 void  ConcatArrays::ConcatStdHep(TClonesArray*  addList,
00121                                  TClonesArray*  permList) {
00122   // Concatenate (permList += addList) and adjust StdHep contents accordingly
00123   // Call another fn to adjust DigiScintHit.trkId() accordingly
00124   //
00125   // MUST BE CALLED ONLY *AFTER* ConcatDigiScintHits() !!!!
00126   //
00127 
00128   if (!addList || !permList ) return;
00129 
00130   const Int_t oldSize = permList->GetEntriesFast();
00131   const Int_t newSize = oldSize + addList->GetEntriesFast();
00132 
00133   for (Int_t i = oldSize; i < newSize; i++) {
00134     TParticle* thisPart = new( (*permList)[i] ) TParticle( *dynamic_cast<TParticle*>(addList->At(i-oldSize)) );
00135 
00136     if ( thisPart ) {
00137       // Adjust indices of this particle's (1st/last) parents & children
00138       for (Int_t j = 0; j < 2; j++) {
00139         if (thisPart->GetMother(j)   >= 0)
00140           thisPart->SetMother(  j, thisPart->GetMother(j)   + oldSize );
00141         if (thisPart->GetDaughter(j) >= 0)
00142           thisPart->SetDaughter(j, thisPart->GetDaughter(j) + oldSize );
00143       } // end loop over Mother/Daughter arrays
00144     } // end if stdhep TParticle is OK
00145   } // end loop over new TParticles
00146 
00147 }
00148 
00149 //__________________________________________________________________________
00150 
00151 void ConcatArrays::OffsetTime(TClonesArray* tcarr, Float_t offsetns){
00152 
00153   if ( !tcarr ) {
00154     return;
00155   }
00156 
00157   // DigiScintHit TClonesArray
00158   if ( tcarr->GetClass()->InheritsFrom("DigiScintHit") ) {
00159 
00160     UInt_t tempSize = tcarr->GetEntriesFast();
00161     
00162     for ( UInt_t i = 0; i < tempSize ; i++) {
00163       DigiScintHit* tempHit = dynamic_cast<DigiScintHit*>(tcarr->At(i));
00164       
00165       Float_t newT1 = tempHit->T1() + offsetns*1.e-9; // time is stored as sec
00166       Float_t newT2 = tempHit->T2() + offsetns*1.e-9; // time is stored as sec
00167 
00168       tempHit->SetT1(newT1);
00169       tempHit->SetT2(newT2);
00170     } // end loop over DigiScintHits
00171 
00172     return;
00173   } // end if DigiScintHit TClonesArray
00174 
00175   // StdHep TClonesArray
00176   if ( tcarr->GetClass()->InheritsFrom("TParticle") ) {
00177     for ( Int_t i = 0; i < tcarr->GetEntriesFast() ; i++) {
00178       TParticle* oldPart = dynamic_cast<TParticle*>(tcarr->At(i));
00179       oldPart->SetProductionVertex(oldPart->Vx(), oldPart->Vy(),
00180                                    oldPart->Vz(), oldPart->T()+offsetns*1.e-9);
00181     } // end loop over StdHep TParticles
00182     return;
00183   } // end if StdHep TClonesArray
00184 
00185   // NeuKin, NuEvtKin, FluxInfo, FluxWgt TClonesArray(s)
00186   if ( ( tcarr->GetClass()->InheritsFrom("REROOT_NeuKin"  ) ||
00187          tcarr->GetClass()->InheritsFrom("NeuKin"         )  ) ||
00188        ( tcarr->GetClass()->InheritsFrom("NuEvtKin"       )  ) ||
00189        ( tcarr->GetClass()->InheritsFrom("REROOT_FluxInfo") ||
00190          tcarr->GetClass()->InheritsFrom("FluxInfo"       )  ) ||
00191        ( tcarr->GetClass()->InheritsFrom("REROOT_FluxWgt" ) ||
00192          tcarr->GetClass()->InheritsFrom("FluxWgt"        )  )  ) {
00193     // Do nothing
00194     return;
00195   } // end if TClonesArray contains no time info
00196 
00197   
00198   
00199   cout << "=E= ConcatArrays: "
00200        << std::string(tcarr->At(0)->ClassName())
00201        << " is not a recognized SimSnarlRecord component: "
00202        << "this should really *never ever* happen, so you "
00203        << "probably broke something!"
00204        << endl; // really and truly
00205 
00206 }
00207 //__________________________________________________________________________
00208 

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